Merge ~alextu/plainbox-provider-pc-sanity:fix-leak-wrong-pkgs-unit-test into ~os369510/plainbox-provider-pc-sanity:fix-leak-wrong-pkgs
- Git
- lp:~alextu/plainbox-provider-pc-sanity
- fix-leak-wrong-pkgs-unit-test
- Merge into fix-leak-wrong-pkgs
Status: | Merged |
---|---|
Merged at revision: | 57f32d940963fa1702a46414430bb9fa4b51968d |
Proposed branch: | ~alextu/plainbox-provider-pc-sanity:fix-leak-wrong-pkgs-unit-test |
Merge into: | ~os369510/plainbox-provider-pc-sanity:fix-leak-wrong-pkgs |
Diff against target: |
497 lines (+245/-50) 8 files modified
README.rst (+3/-0) bin/edid_continuous_frequency_check.py (+13/-11) bin/idle-delay-60.sh (+2/-0) bin/screen-pkg-not-public.sh (+56/-36) debian/control (+1/-1) debian/rules (+4/-1) po/POTFILES.in (+1/-1) test/test-screen-pkg-not-public.bats (+165/-0) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
jeremyszu | Approve | ||
Shih-Yuan Lee (community) | Needs Fixing | ||
Bin Li | Pending | ||
Yuan-Chen Cheng | Pending | ||
Review via email: mp+391868@code.launchpad.net |
Commit message
Description of the change
Alex Tu (alextu) wrote : | # |
Alex Tu (alextu) wrote : | # |
the log of build debian package after adopt shellcheck and bats in debian/rules: https:/
Alex Tu (alextu) wrote : | # |
a test build passed in docker container : https:/
Alex Tu (alextu) wrote : | # |
Shih-Yuan Lee (fourdollars) wrote : | # |
There are some conflictions.
Alex Tu (alextu) wrote : | # |
I rebased to target branch ~os369510/
╰─>bats test/test-
✓ allow pkgs came from ubuntu archive
✓ screen out pkgs we hacked
✓ screen out pkgs only in unexpected archive.
✓ screen out pkgs not in any archive.
✓ screen out pkgs only on oem archive.
5 tests, 0 failures
And it build passed in focal docker container:
https:/
Alex Tu (alextu) wrote : | # |
u@u-Latitude-
✓ run_main() reflect the JOB_STATUS
✓ allow pkgs came from ubuntu archive
✓ screen out pkgs we hacked
✓ screen out pkgs only in unexpected archive.
✓ screen out pkgs not in any archive.
✓ screen out pkgs only on oem archive.
6 tests, 0 failures
Rex Tsai (chihchun) wrote : | # |
Good work on the code changes and the unit test.
This MP includes adding new test case for bin/edid_
Why this MP is targeting ~os369510/
jeremyszu (os369510) wrote : | # |
@Alex,
Please review following comments.
I think those are easy to fix.
Alex Tu (alextu) wrote : | # |
> Good work on the code changes and the unit test.
>
> This MP includes adding new test case for
> bin/edid_
> not-public.sh. I would prefer to do it separately.
>
> Why this MP is targeting ~os369510/
> pkgs but not the project branch?
Because this MP is triggered by the difficulty of reviewing ~os369510/
Alex Tu (alextu) wrote : | # |
done the chage:
ubuntu@
https:/
$ bats test/test-
✓ run_main() reflect the JOB_STATUS
✓ allow pkgs came from ubuntu archive
✓ screen out pkgs we hacked
✓ screen out pkgs only in unexpected archive.
✓ screen out pkgs not in any archive.
✓ screen out pkgs only on oem archive.
6 tests, 0 failures
Alex Tu (alextu) wrote : | # |
also the autopkgtest result after merging master : https:/
autopkgresult :
https:/
Alex Tu (alextu) wrote : | # |
also the autopkgtest result after merging master : https:/
$ ./autopkgtest.sh 2>&1
https:/
jeremyszu (os369510) wrote : | # |
See my comment below.
Preview Diff
1 | diff --git a/README.rst b/README.rst |
2 | index 702788e..d8af49f 100644 |
3 | --- a/README.rst |
4 | +++ b/README.rst |
5 | @@ -2,3 +2,6 @@ Plainbox Provider for Kernel SRU testing |
6 | ======================================== |
7 | |
8 | This provider contains test cases and a test plan for pc sanity testing. |
9 | + |
10 | +It depends on packages from ppa:checkbox-dev/ppa in build time. |
11 | +The launchpad recipe build it daily : https://code.launchpad.net/~oem-solutions-engineers/+recipe/plainbox-provider-pc-sanity-daily-1 |
12 | diff --git a/bin/edid_continuous_frequency_check.py b/bin/edid_continuous_frequency_check.py |
13 | index 368b992..5db54a5 100755 |
14 | --- a/bin/edid_continuous_frequency_check.py |
15 | +++ b/bin/edid_continuous_frequency_check.py |
16 | @@ -5,14 +5,16 @@ import os |
17 | import glob |
18 | import argparse |
19 | |
20 | + |
21 | def is_laptop(): |
22 | with open('/sys/class/dmi/id/chassis_type', 'r') as fobj: |
23 | - chassis_type=fobj.read().replace('\n', '') |
24 | + chassis_type = fobj.read().replace('\n', '') |
25 | if chassis_type == '10' or chassis_type == '9' or chassis_type == '13': |
26 | return True |
27 | print("Not laptop, notebook or AIO platform, abort EDID check.") |
28 | return False |
29 | |
30 | + |
31 | def find_internal_panel_edid(): |
32 | """ Find internal panel edid """ |
33 | drmdir = '/sys/class/drm/' |
34 | @@ -55,7 +57,7 @@ def get_horizontal_addressable_video_in_pixels(data_block_of_DTD): |
35 | """ |
36 | havip = bytearray((data_block_of_DTD[4] >> 4).to_bytes(1, byteorder='big')) |
37 | havip.append(data_block_of_DTD[2]) |
38 | - # print("DTD: Horizontal Addressable Video in Pixels: %d" % int.from_bytes(havip, byteorder='big') ) |
39 | + # print("DTD: Horizontal Addressable Video in Pixels: %d" % int.from_bytes(havip, byteorder='big') ) # noqa: E501 |
40 | return int.from_bytes(havip, byteorder='big') |
41 | |
42 | |
43 | @@ -63,22 +65,22 @@ def maximum_horizontal_active_pixels(byte12, byte13): |
44 | return (8 * (byte13 + 256 * (0x03 & byte12))) |
45 | |
46 | |
47 | -def check_display_range_limits_descriptor(data_block_of_DRLD, horizontal_address_video_in_pixels): |
48 | +def check_display_range_limits_descriptor(data_block_of_DRLD, horizontal_address_video_in_pixels): # noqa: E501 |
49 | """ Check Display Range Limits Descriptor with CVT support |
50 | Address: 0x48h |
51 | Size: 18 bytes |
52 | """ |
53 | # Debug dump DRLD |
54 | - # print("DRLD: Dump: %02X" % int.from_bytes(data_block_of_DRLD, byteorder='big')) |
55 | + # print("DRLD: Dump: %02X" % int.from_bytes(data_block_of_DRLD, byteorder='big'))# noqa: E501 |
56 | |
57 | # check tag 0xFD |
58 | if (data_block_of_DRLD[3] == 0xfd): |
59 | if (data_block_of_DRLD[10] == 0x04): |
60 | - if (data_block_of_DRLD[5] < data_block_of_DRLD[6]) and (data_block_of_DRLD[7] < data_block_of_DRLD[8]): |
61 | - if horizontal_address_video_in_pixels == maximum_horizontal_active_pixels(data_block_of_DRLD[12], data_block_of_DRLD[13]): |
62 | + if (data_block_of_DRLD[5] < data_block_of_DRLD[6]) and (data_block_of_DRLD[7] < data_block_of_DRLD[8]): # noqa: E501 |
63 | + if horizontal_address_video_in_pixels == maximum_horizontal_active_pixels(data_block_of_DRLD[12], data_block_of_DRLD[13]): # noqa: E501 |
64 | return True |
65 | else: |
66 | - print("horizontal_address_video_in_pixels != maximum_horizontal_active_pixels ") |
67 | + print("horizontal_address_video_in_pixels != maximum_horizontal_active_pixels ") # noqa: E501 |
68 | else: |
69 | print("Minimum/Maximum Vertical/Horizontal Freq value error") |
70 | else: |
71 | @@ -90,7 +92,7 @@ def check_display_range_limits_descriptor(data_block_of_DRLD, horizontal_address |
72 | |
73 | def main(): |
74 | parser = argparse.ArgumentParser() |
75 | - parser.add_argument("--edid", help="path of a EDID file from /sys/class/drm/", type=str) |
76 | + parser.add_argument("--edid", help="path of a EDID file from /sys/class/drm/", type=str) # noqa: E501 |
77 | args = parser.parse_args() |
78 | if not is_laptop(): |
79 | return 0 |
80 | @@ -101,13 +103,13 @@ def main(): |
81 | edidfile = args.edid |
82 | |
83 | with open(edidfile, 'rb') as fobj: |
84 | - version, revision = get_edid_version(read_edid(fobj, 0x12, 1), read_edid(fobj, 0x13, 1)) |
85 | + version, revision = get_edid_version(read_edid(fobj, 0x12, 1), read_edid(fobj, 0x13, 1)) # noqa: E501 |
86 | if version == 1 and revision >= 4: |
87 | if is_continuous_frequency_display(read_edid(fobj, 0x18, 1)): |
88 | - if check_display_range_limits_descriptor(read_edid(fobj, 0x48, 18), get_horizontal_addressable_video_in_pixels(read_edid(fobj, 0x36, 18))): |
89 | + if check_display_range_limits_descriptor(read_edid(fobj, 0x48, 18), get_horizontal_addressable_video_in_pixels(read_edid(fobj, 0x36, 18))): # noqa: E501 |
90 | print("EDID Display Range Limits Descriptor checke: pass") |
91 | else: |
92 | - raise SystemExit("EDID Display Range Limits Descriptor check failed!") |
93 | + raise SystemExit("EDID Display Range Limits Descriptor check failed!") # noqa: E501 |
94 | else: |
95 | print("Display is noncontinuous frequency") |
96 | else: |
97 | diff --git a/bin/idle-delay-60.sh b/bin/idle-delay-60.sh |
98 | index 37e579d..db18e33 100755 |
99 | --- a/bin/idle-delay-60.sh |
100 | +++ b/bin/idle-delay-60.sh |
101 | @@ -1 +1,3 @@ |
102 | +#!/bin/bash |
103 | + |
104 | gsettings set org.gnome.desktop.session idle-delay 60 |
105 | diff --git a/bin/screen-pkg-not-public.sh b/bin/screen-pkg-not-public.sh |
106 | old mode 100644 |
107 | new mode 100755 |
108 | index 3eec17c..a3a3ae8 |
109 | --- a/bin/screen-pkg-not-public.sh |
110 | +++ b/bin/screen-pkg-not-public.sh |
111 | @@ -1,22 +1,26 @@ |
112 | #!/bin/bash |
113 | |
114 | set -e |
115 | +readonly pkg_pass="0" |
116 | +readonly pkg_failed="1" |
117 | allowlist_git="https://git.launchpad.net/~oem-solutions-engineers/pc-enablement/+git/oem-gap-allow-list" |
118 | +pf_meta_pkg="" |
119 | +pf_factory_meta_pkg="" |
120 | oem="" |
121 | platform="" |
122 | allowlst_folder="" |
123 | -STATUS="pass" |
124 | +JOB_STATUS="pass" |
125 | clean() { |
126 | rm -rf "$allowlst_folder" |
127 | [ -z "$1" ] || exit "$1" |
128 | - [ "$STATUS" != "pass" ] && exit 1 |
129 | + [ "$JOB_STATUS" != "pass" ] && exit 1 |
130 | exit 0 |
131 | } |
132 | prepare() { |
133 | oem="$(grep -q sutton <(ubuntu-report show | grep DCD) && echo sutton)" ||\ |
134 | oem="$(grep -q stella <(ubuntu-report show | grep DCD) && echo stella)" ||\ |
135 | oem="$(grep -q somerville <(ubuntu-report show | grep DCD) && echo somerville)" ||\ |
136 | - (>&2 echo "[ERROR][CODE]got an empty OEM codename in ${FUNCNAME[1]}" && clean 1) |
137 | + (>&2 echo "[ERROR][CODE]got an empty OEM codename in ${FUNCNAME[0]}" && clean 1) |
138 | case "$oem" in |
139 | "somerville") |
140 | platform="$(ubuntu-report show | grep DCD | awk -F'+' '{print $2}')" |
141 | @@ -33,30 +37,33 @@ prepare() { |
142 | done |
143 | ;; |
144 | *) |
145 | - >&2 echo "[ERROR][CODE]we should not be here in ${FUNCNAME[1]} : ${LINENO}" && clean 1 |
146 | + >&2 echo "[ERROR][CODE]we should not be here in ${FUNCNAME[0]} : ${LINENO}" && clean 1 |
147 | ;; |
148 | esac |
149 | - [ -z "$platform" ] && (>&2 echo "[ERROR][CODE]got an empty platform name for $oem in ${FUNCNAME[1]}" && clean 1) |
150 | + [ -n "$platform" ] || (>&2 echo "[ERROR][CODE]got an empty platform name for $oem in ${FUNCNAME[0]}" && clean 1) |
151 | (sudo apt-get update > /dev/null || (>&2 echo "[ERROR]apt-get update failed, please check it." | exit 1)) && sudo apt-get install -y git > /dev/null |
152 | + pf_meta_pkg="$(dpkg -S /etc/apt/sources.list.d/oem-"${oem}"-*-meta.list | awk '{print $1}' | sed 's/://Ig')" |
153 | + pf_factory_meta_pkg="${pf_meta_pkg/oem-${oem}-/oem-${oem}-factory-}" |
154 | echo "[INFO] getting allowlist from $allowlist_git." |
155 | [ -n "$allowlist_git" ] &&\ |
156 | - (git clone --depth=1 "$allowlist_git" || (>&2 echo "[ERROR]git clone ""$allowlist_git"" filed, please check it." | exit 1)) &&\ |
157 | - allowlst_folder="$PWD"/"$(basename "$allowlist_git")" |
158 | + allowlst_folder="$PWD"/"$(basename "$allowlist_git")" &&\ |
159 | + rm -rf "$allowlst_folder" &&\ |
160 | + (git clone --depth=1 "$allowlist_git" || (>&2 echo "[ERROR]git clone ""$allowlist_git"" failed, please check it." | exit 1)) |
161 | echo "[INFO] git hash of current allowlist: $(git -C "$allowlst_folder" rev-parse --short HEAD)" |
162 | } |
163 | pkg_need_allowing() { |
164 | - [ -z "$1" ] && >&2 echo "[ERROR][CODE]got an empty pkg in ${FUNCNAME[1]}" && clean 1 |
165 | - >&2 echo "[ERROR] Please send a MP to $allowlist_git for manager review $1" && STATUS="failed" |
166 | + [ -n "$1" ] || ( >&2 echo "[ERROR][CODE]got an empty pkg in ${FUNCNAME[0]}" && clean 1) |
167 | + >&2 echo "[ERROR] Please send a MP to $allowlist_git for manager review $1" && JOB_STATUS="failed" |
168 | } |
169 | pkg_need_update() { |
170 | - [ -z "$1" ] && >&2 echo "[ERROR][CODE]got an empty pkg in ${FUNCNAME[1]}" && clean 1 |
171 | + [ -n "$1" ] && (>&2 echo "[ERROR][CODE]got an empty pkg in ${FUNCNAME[0]}" && clean 1) |
172 | >&2 echo "[ERROR] find a update-able pkg: $1 $2" && pkg_need_allowing "$1" |
173 | } |
174 | # return 0 for allowing |
175 | # return 1 for not allowing |
176 | if_allowing() { |
177 | local allowed="NO" |
178 | - [ -z "$1" ] && >&2 echo "[ERROR][CODE]got an empty pkg in ${FUNCNAME[1]}" && clean 1 |
179 | + [ -n "$1" ] || (>&2 echo "[ERROR][CODE]got an empty pkg in ${FUNCNAME[0]}" && clean 1) |
180 | |
181 | # check if the pkg on allow list. |
182 | for F in "$allowlst_folder"/testtools "$allowlst_folder"/common "$allowlst_folder"/"$oem"/common "$allowlst_folder"/"$oem"/"$platform"; do |
183 | @@ -71,24 +78,16 @@ if_allowing() { |
184 | fi |
185 | } |
186 | pkg_not_public() { |
187 | - [ -z "$1" ] && >&2 echo "[ERROR][CODE]got an empty pkg in" "${FUNCNAME[1]}" && clean 1 |
188 | + [ -n "$1" ] || (>&2 echo "[ERROR][CODE]got an empty pkg in" "${FUNCNAME[0]}" && clean 1) |
189 | # check if the pkg on allow list. |
190 | - if_allowing "$1" || (>&2 echo "[ERROR] find a packge not on public archive:" "$1" "$2" && pkg_need_allowing "$1") |
191 | + if_allowing "$1" || (>&2 echo "[ERROR] find a packge not on public archive:" "$1" "$2" && pkg_need_allowing "$1" && return $pkg_failed) |
192 | } |
193 | -prepare |
194 | -echo "[INFO] staring screen all installed packages." |
195 | - |
196 | -pf_meta_pkg="$(dpkg -S /etc/apt/sources.list.d/oem-"${oem}"-*-meta.list | awk '{print $1}' | sed 's/://Ig')" |
197 | -pf_factory_meta_pkg="${pf_meta_pkg/oem-${oem}-/oem-${oem}-factory-}" |
198 | - |
199 | -while IFS= read -r line; do |
200 | - progress=">""$progress" |
201 | - [ "${#progress}" == "70" ] && echo "$progress" && progress="" |
202 | - |
203 | +screen_pkg() { |
204 | + [ -n "$1" ] || (>&2 echo "[ERROR][CODE]got an empty input in" "${FUNCNAME[0]}" && clean 1) |
205 | + line="$1" |
206 | pkg_name="$(echo "${line}" | awk '{print $2}')" |
207 | pkg_ver="$(echo "${line}" | awk '{print $3}')" |
208 | pkg_curr_madison="$(apt-cache madison "${pkg_name}" | grep "$pkg_ver" || true)" |
209 | - |
210 | # FIXME: I don't think the upgradable is need to in "id: miscellanea/screen-pkg-not-public" |
211 | # Should have the other something like "id: miscellanea/check-oem-pkg-updatable" |
212 | # Remove this section can speed up this test scope |
213 | @@ -96,7 +95,7 @@ while IFS= read -r line; do |
214 | # TODO: detect somerville only? |
215 | if [ -z "${pkg_ver##*oem*}" ] || [ -z "${pkg_ver##*somerville*}" ]; then |
216 | if if_allowing "$pkg_name"; then |
217 | - continue |
218 | + return $pkg_pass |
219 | else |
220 | can_pkg_ver="$(apt-cache policy "$pkg_name" | grep Candidate | awk '{print $2}')" |
221 | if dpkg --compare-versions "$can_pkg_ver" "gt" "$pkg_ver"; then |
222 | @@ -115,10 +114,13 @@ while IFS= read -r line; do |
223 | if [ -n "${pkg_can_madison}" ] && |
224 | { [ -z "${pkg_can_madison##*security.ubuntu.com/ubuntu*}" ] || |
225 | [ -z "${pkg_can_madison##*archive.ubuntu.com/ubuntu*}" ]; }; then |
226 | - continue |
227 | + return $pkg_pass |
228 | + fi |
229 | + if pkg_not_public "$pkg_name" "$pkg_ver"; then |
230 | + return $pkg_pass |
231 | + else |
232 | + return $pkg_failed |
233 | fi |
234 | - pkg_not_public "$pkg_name" "$pkg_ver" |
235 | - continue |
236 | fi |
237 | |
238 | # If the installed package is from ubuntu-archive then we're good |
239 | @@ -126,7 +128,7 @@ while IFS= read -r line; do |
240 | # all source list are under control at lease before GM) |
241 | if [ -z "${pkg_curr_madison##*security.ubuntu.com/ubuntu*}" ] || |
242 | [ -z "${pkg_curr_madison##*archive.ubuntu.com/ubuntu*}" ]; then |
243 | - continue |
244 | + return $pkg_pass |
245 | fi |
246 | |
247 | # If the installed package is from canonical-archive then we need to |
248 | @@ -134,15 +136,33 @@ while IFS= read -r line; do |
249 | if [ -z "${pkg_curr_madison##*archive.canonical.com*}" ]; then |
250 | # If the package is platform meta package then it should be control by meta generator |
251 | if [ "$pkg_name" == "$pf_meta_pkg" ] || [ "$pkg_name" == "$pf_factory_meta_pkg" ]; then |
252 | - continue |
253 | + return $pkg_pass |
254 | fi |
255 | # Otherwise, need to review |
256 | - pkg_not_public "$pkg_name" "$pkg_ver" |
257 | - continue |
258 | + if pkg_not_public "$pkg_name" "$pkg_ver"; then |
259 | + return $pkg_pass |
260 | + else |
261 | + return $pkg_failed |
262 | + fi |
263 | fi |
264 | - |
265 | # For unkown source of package (e.g. from a ppa), then review |
266 | - pkg_not_public "$pkg_name" "$pkg_ver" |
267 | + if pkg_not_public "$pkg_name" "$pkg_ver"; then |
268 | + return $pkg_pass |
269 | + else |
270 | + return $pkg_failed |
271 | + fi |
272 | +} |
273 | |
274 | -done < <(dpkg -l | grep 'ii') |
275 | -clean |
276 | +run_main() { |
277 | + prepare |
278 | + >&2 echo "[INFO] staring screen all installed packages." |
279 | + while IFS= read -r line; do |
280 | + progress=">""$progress" |
281 | + [ "${#progress}" == "70" ] && echo "$progress" && progress="" |
282 | + screen_pkg "$line" || JOB_STATUS="failed" |
283 | + done < <(dpkg -l | grep 'ii') |
284 | + clean |
285 | +} |
286 | +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then |
287 | + run_main |
288 | +fi |
289 | diff --git a/debian/control b/debian/control |
290 | index 5c17129..0912a6e 100644 |
291 | --- a/debian/control |
292 | +++ b/debian/control |
293 | @@ -3,7 +3,7 @@ Section: utils |
294 | Priority: optional |
295 | Maintainer: Commercial Engineering <commercial-engineering@canonical.com> |
296 | Standards-Version: 3.9.7 |
297 | -Build-Depends: debhelper (>= 9), dh-modaliases |
298 | +Build-Depends: debhelper (>= 9), dh-modaliases, intltool, python3-checkbox-ng, plainbox-provider-checkbox, flake8, bats, shellcheck |
299 | Vcs-Browser: https://code.launchpad.net/~ville-team/ville/+git/plainbox-provider-pc-sanity |
300 | |
301 | Package: plainbox-provider-pc-sanity |
302 | diff --git a/debian/rules b/debian/rules |
303 | index 02c4840..1265262 100755 |
304 | --- a/debian/rules |
305 | +++ b/debian/rules |
306 | @@ -11,7 +11,10 @@ override_dh_auto_build: |
307 | python3 manage.py i18n |
308 | |
309 | override_dh_auto_test: |
310 | - python3 manage.py validate |
311 | + python3 manage.py validate |
312 | + shellcheck bin/*.sh |
313 | + bats test/*.bat |
314 | + flake8 bin/*.py |
315 | |
316 | override_dh_auto_install: |
317 | python3 manage.py install --prefix=/usr --layout=unix \ |
318 | diff --git a/po/POTFILES.in b/po/POTFILES.in |
319 | index f0e418b..a3aa462 100644 |
320 | --- a/po/POTFILES.in |
321 | +++ b/po/POTFILES.in |
322 | @@ -1,3 +1,3 @@ |
323 | [encoding: UTF-8] |
324 | -[type: gettext/rfc822deb] units/pc-sanity.pxu |
325 | +[type: gettext/rfc822deb] units/pc-sanity/pc-sanity.pxu |
326 | manage.py |
327 | diff --git a/test/test-screen-pkg-not-public.bats b/test/test-screen-pkg-not-public.bats |
328 | new file mode 100644 |
329 | index 0000000..9e8bb5a |
330 | --- /dev/null |
331 | +++ b/test/test-screen-pkg-not-public.bats |
332 | @@ -0,0 +1,165 @@ |
333 | +#!/usr/bin/env bats |
334 | + |
335 | +# execute this test file by `bats test/test-screen-pkg-not-public.bats` |
336 | +BIN_FOLDER="bin" |
337 | + |
338 | +function if_allowing() { |
339 | + return 1 |
340 | +} |
341 | + |
342 | +function setup() { |
343 | + source "$BIN_FOLDER"/screen-pkg-not-public.sh |
344 | + oem="somerville" |
345 | + platform="fossa-melisa" |
346 | +} |
347 | + |
348 | +@test "run_main() reflect the JOB_STATUS" { |
349 | + set -e |
350 | + status_failed=1 |
351 | + status_passed=0 |
352 | + function screen_pkg(){ |
353 | + return "$status_simulate" |
354 | + } |
355 | + function prepare(){ |
356 | + echo "empty" |
357 | + } |
358 | + function clean(){ |
359 | + echo "empty" |
360 | + } |
361 | + function dpkg(){ |
362 | + echo "ii" |
363 | + } |
364 | + |
365 | + status_simulate=$status_passed |
366 | + # we expect it pass. |
367 | + run_main |
368 | + [ "$JOB_STATUS" == "pass" ] |
369 | + |
370 | + status_simulate=$status_failed |
371 | + # we expect it failed. |
372 | + run_main |
373 | + [ "$JOB_STATUS" == "failed" ] |
374 | + |
375 | +} |
376 | + |
377 | +function apt-cache() { |
378 | + case "$1" in |
379 | + "madison") |
380 | + echo "$aptcache_medison_string" |
381 | + ;; |
382 | + "policy") |
383 | + echo "$apt_cache_policy_string" |
384 | + ;; |
385 | + *) |
386 | + return 1; |
387 | + ;; |
388 | + esac |
389 | +} |
390 | + |
391 | +@test "allow pkgs came from ubuntu archive" { |
392 | + set -e |
393 | + aptcache_medison_string=" |
394 | + ubuntu-desktop | 1.450.2 | http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages |
395 | + ubuntu-desktop | 1.450 | http://archive.ubuntu.com/ubuntu focal/main amd64 Packages |
396 | + " |
397 | + apt_cache_policy_string="\ |
398 | + ubuntu-desktop:\ |
399 | + Installed: 1.450.2\ |
400 | + Candidate: 1.450.2\ |
401 | + Version table:\ |
402 | + *** 1.450.2 500\ |
403 | + 500 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages\ |
404 | + 100 /var/lib/dpkg/status\ |
405 | + 1.450 500\ |
406 | + 500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages\ |
407 | + " |
408 | + export -f apt-cache |
409 | + # we expect it passed. |
410 | + run screen_pkg "ii ubuntu-desktop 1.450.2 amd64 The Ubuntu desktop system" |
411 | + [ "$status" -eq 0 ] |
412 | + unset -f apt-cache |
413 | + |
414 | +} |
415 | + |
416 | +@test "screen out pkgs we hacked" { |
417 | + set -e |
418 | + dpkg_list_string="ii ubiquity 20.04.15.2somerville2 amd64 Ubuntu live CD installer" |
419 | + aptcache_medison_string=" |
420 | + ubiquity | 20.04.15.2 | http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages |
421 | + ubiquity | 20.04.15 | http://archive.ubuntu.com/ubuntu focal/main amd64 Packages |
422 | + " |
423 | + apt_cache_policy_string=" |
424 | + ubiquity: |
425 | + Installed: 20.04.15.2somerville2 |
426 | + Candidate: 20.04.15.2somerville2 |
427 | + Version table: |
428 | + *** 20.04.15.2somerville2 100 |
429 | + 100 /var/lib/dpkg/status |
430 | + 20.04.15.2 500 |
431 | + 500 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages |
432 | + 20.04.15 500 |
433 | + 500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages |
434 | + " |
435 | + export -f apt-cache |
436 | + # we expect it failed. |
437 | + run screen_pkg "$dpkg_list_string" |
438 | + [ "$status" -eq 1 ] |
439 | + unset -f apt-cache |
440 | +} |
441 | + |
442 | +@test "screen out pkgs only in unexpected archive." { |
443 | + set -e |
444 | + dpkg_list_string="ii fwts 20.09.00-0ubuntu1~f amd64 FirmWare Test Suite" |
445 | + aptcache_medison_string=" |
446 | + fwts | 20.09.00-0ubuntu1~f | http://ppa.launchpad.net/checkbox-dev/ppa/ubuntu focal/main amd64 Packages |
447 | + fwts | 20.03.00-0ubuntu1 | http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages |
448 | + " |
449 | + apt_cache_policy_string=" |
450 | + fwts: |
451 | + Installed: 20.09.00-0ubuntu1~f |
452 | + Candidate: 20.09.00-0ubuntu1~f |
453 | + Version table: |
454 | + *** 20.09.00-0ubuntu1~f 500 |
455 | + 500 http://ppa.launchpad.net/checkbox-dev/ppa/ubuntu focal/main amd64 Packages |
456 | + 100 /var/lib/dpkg/status |
457 | + 20.03.00-0ubuntu1 500 |
458 | + 500 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages |
459 | + " |
460 | + |
461 | + export -f apt-cache |
462 | + # we expect it failed. |
463 | + run screen_pkg "$dpkg_list_string" |
464 | + [ "$status" -eq 1 ] |
465 | + unset -f apt-cache |
466 | +} |
467 | + |
468 | +@test "screen out pkgs not in any archive." { |
469 | + set -e |
470 | + # we expect it failed. |
471 | + run screen_pkg "ii a-nonexisted-pkg 1.187.3 all Firmware for Linux kernel drivers" |
472 | + [ "$status" -eq 1 ] |
473 | + echo in bat: JOB_STATUS=$JOB_STATUS |
474 | +} |
475 | + |
476 | +@test "screen out pkgs only on oem archive." { |
477 | + set -e |
478 | + dpkg_list_string="ii pkg-only-on-oemarchive 20.04ubuntu7 all Firmware for Linux kernel drivers" |
479 | + aptcache_medison_string=" |
480 | + pkg-only-on-oem-archive | 20.04ubuntu7 | http://dell.archive.canonical.com focal/somerville-melisa amd64 Packages |
481 | + " |
482 | + apt_cache_policy_string=" |
483 | + pkg-only-on-oem-archive: |
484 | + Installed: 20.04ubuntu7 |
485 | + Candidate: 20.04ubuntu7 |
486 | + Version table: |
487 | + *** 20.04ubuntu7 500 |
488 | + 500 http://dell.archive.canonical.com focal/somerville-melisa amd64 Packages |
489 | + 500 http://dell.archive.canonical.com focal/somerville-melisa i386 Packages |
490 | + " |
491 | + |
492 | + export -f apt-cache |
493 | + # we expect it failed. |
494 | + run screen_pkg "$dpkg_list_string" |
495 | + [ "$status" -eq 1 ] |
496 | + unset -f apt-cache |
497 | +} |
$ bats test/test- screen- pkg-not- public. bat ✓ allow pkgs came from ubuntu archive
✓ screen out pkgs we hacked
✓ screen out pkgs only in unexpected archive.
✓ screen out pkgs not in any archive.
✓ screen out pkgs only on oem archive.
5 tests, 0 failures
tested the changed screen- pkg-not- public. sh on ubuntu@ dell-bto- focal-fossa- 201810- 26535: /paste. ubuntu. com/p/hPDZgsCNb j/
https:/