-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathchwd_spec.lua
More file actions
188 lines (168 loc) · 7.71 KB
/
Copy pathchwd_spec.lua
File metadata and controls
188 lines (168 loc) · 7.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
describe("Profile parsing", function()
_G._TEST = true
package.path = 'scripts/?;' .. package.path
local chwd = require("chwd")
describe("Valid cases", function()
local profiles = chwd.parse_profiles("tests/profiles/graphic_drivers-profiles-test.toml")
local name = "nvidia-dkms"
it("Profiles are available", function()
assert.are_not.same(profiles, {})
end)
local profile = profiles[name]
it("Search for profile", function()
assert.truthy(profile)
end)
describe("Attributes", function()
local packages, hooks = chwd.get_profile(profiles, name)
it("Packages", function()
assert.are.equals(packages,
"nvidia-utils egl-wayland nvidia-settings opencl-nvidia lib32-opencl-nvidia lib32-nvidia-utils libva-nvidia-driver vulkan-icd-loader lib32-vulkan-icd-loader")
end)
it("Hooks", function()
assert.truthy(hooks)
end)
it("Post remove hook", function()
assert.are.equals(hooks['post_remove'], [[
rm -f /etc/mkinitcpio.conf.d/10-chwd.conf
mkinitcpio -P
]])
end)
it("Post install hook", function()
assert.are.equals(hooks['post_install'], [[
cat <<EOF >/etc/mkinitcpio.conf.d/10-chwd.conf
# This file is automatically generated by chwd. PLEASE DO NOT EDIT IT.
MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm)
EOF
mkinitcpio -P
]])
end)
it("Conditional packages hook", function()
assert.are.equals(hooks['conditional_packages'], [[
kernels="$(pacman -Qqs "^linux-cachyos")"
modules=""
for kernel in $kernels; do
case "$kernel" in
*-headers|*-zfs);;
*-nvidia) modules+=" ${kernel}";;
*) modules+=" ${kernel}-nvidia";;
esac
done
# Fallback if there are no kernels with pre-built modules
[ -z "$modules" ] && modules="nvidia-dkms"
echo "$modules"
]])
end)
end)
local child_name = "nvidia-dkms.40xxcards"
local child_profile = profiles[child_name]
it("Search for child profile", function()
assert.truthy(child_profile)
end)
describe("Inheritance", function()
local packages, hooks = chwd.get_profile(profiles, child_name)
it("Inherit parent packages", function()
assert.are.equals(packages,
"nvidia-utils egl-wayland nvidia-settings opencl-nvidia lib32-opencl-nvidia lib32-nvidia-utils libva-nvidia-driver vulkan-icd-loader lib32-vulkan-icd-loader")
end)
it("Inherit some parent hook", function()
assert.are.equals(hooks['post_remove'], [[
rm -f /etc/mkinitcpio.conf.d/10-chwd.conf
mkinitcpio -P
]])
end)
it("Child post install hook", function()
assert.are.equals(hooks['post_install'], [[
cat <<EOF >/etc/mkinitcpio.conf.d/10-chwd.conf
# This file is automatically generated by chwd. PLEASE DO NOT EDIT IT.
MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm)
EOF
mkinitcpio -P
]])
end)
end)
describe("Handheld profiles without explicit packages", function()
local handheld_profiles = chwd.parse_profiles("profiles/pci/handhelds/profiles.toml")
it("Parent handheld profile parsed", function()
assert.truthy(handheld_profiles["handheld"])
assert.are.equals(handheld_profiles["handheld"].packages, "steamos-manager inputplumber steamos-powerbuttond")
end)
it("ROG Ally profile inherits packages and parses its own hooks", function()
assert.truthy(handheld_profiles["handheld.rog-ally"])
local packages, hooks = chwd.get_profile(handheld_profiles, "handheld.rog-ally")
assert.are.equals(packages, "steamos-manager inputplumber steamos-powerbuttond")
assert.truthy(hooks["post_install"])
assert.truthy(hooks["post_install"]:find("Ally chwd installing%.%.%."))
assert.truthy(hooks["post_install"]:find("/etc/wireplumber/wireplumber%.conf%.d"))
assert.truthy(hooks["post_remove"])
assert.truthy(hooks["post_remove"]:find("Ally chwd removing%.%.%."))
assert.truthy(hooks["conditional_packages"])
assert.truthy(hooks["conditional_packages"]:find("LENOVO"))
end)
it("MSI Claw profile inherits packages and parses its own hooks", function()
assert.truthy(handheld_profiles["handheld.msi-claw"])
local packages, hooks = chwd.get_profile(handheld_profiles, "handheld.msi-claw")
assert.are.equals(packages, "steamos-manager inputplumber steamos-powerbuttond")
assert.truthy(hooks["post_install"])
assert.truthy(hooks["post_install"]:find("Claw chwd installing%.%.%."))
assert.truthy(hooks["post_install"]:find("chwd%-msi%-claw%.conf"))
assert.truthy(hooks["post_remove"])
assert.truthy(hooks["post_remove"]:find("Claw chwd removing%.%.%."))
end)
end)
describe("Packages inspection", function()
local lfs = require("lfs")
local function search(path, t)
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path .. '/' .. file
local attr = lfs.attributes(f)
assert(type(attr) == "table")
if attr.mode == "directory" then
search(f, t)
else
if f:match('.toml$') then
t[#t + 1] = f
end
end
end
end
end
local available_profiles = {}
search("./profiles", available_profiles)
it("Packages are available in repo", function()
for _, file in ipairs(available_profiles) do
local profiles = chwd.parse_profiles(file)
for pname, _ in pairs(profiles) do
local packages = chwd.get_profile(profiles, pname)
print(string.format("Checking profile %s for available packages: %s...", pname, packages))
local _, _, exitcode = os.execute("pacman -Sp " .. packages .. " 1>/dev/null")
assert.True(exitcode == 0)
end
end
end)
end)
end)
describe("shell_quote", function()
it("wraps values in single quotes", function()
assert.are.equals(chwd.shell_quote("/var/cache/pacman/pkg"), "'/var/cache/pacman/pkg'")
end)
it("escapes embedded single quotes", function()
assert.are.equals(chwd.shell_quote("a'b"), "'a'\\''b'")
end)
it("leaves shell metacharacters as literals inside the quotes", function()
assert.are.equals(chwd.shell_quote("/tmp/x; id #"), "'/tmp/x; id #'")
end)
end)
describe("Invalid cases", function()
it("Profiles are not available", function()
assert.are.same(chwd.parse_profiles("/dev/null"), {})
end)
local profiles = chwd.parse_profiles("tests/profiles/graphic_drivers-invalid-profiles-test.toml")
it("Non-existing profile", function()
assert.is.falsy(profiles['unknown'])
end)
it("Unspecified packages", function()
assert.is.falsy(profiles['invalid'].packages)
end)
end)
end)