summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/lib/oeqa/selftest/cases/debuginfod.py67
1 files changed, 59 insertions, 8 deletions
diff --git a/meta/lib/oeqa/selftest/cases/debuginfod.py b/meta/lib/oeqa/selftest/cases/debuginfod.py
index 3c40119282..37f51760fb 100644
--- a/meta/lib/oeqa/selftest/cases/debuginfod.py
+++ b/meta/lib/oeqa/selftest/cases/debuginfod.py
@@ -12,6 +12,36 @@ from oeqa.utils.commands import bitbake, get_bb_var, runqemu
12 12
13 13
14class Debuginfod(OESelftestTestCase): 14class Debuginfod(OESelftestTestCase):
15
16 def wait_for_debuginfod(self, port):
17 """
18 debuginfod takes time to scan the packages and requesting too early may
19 result in a test failure if the right packages haven't been scanned yet.
20
21 Request the metrics endpoint periodically and wait for there to be no
22 busy scanning threads.
23
24 Returns True if debuginfod is ready, False if we timed out
25 """
26 import time, urllib
27
28 # Wait a minute
29 countdown = 6
30 delay = 10
31
32 while countdown:
33 time.sleep(delay)
34 try:
35 with urllib.request.urlopen("http://localhost:%d/metrics" % port) as f:
36 lines = f.read().decode("ascii").splitlines()
37 if "thread_busy{role=\"scan\"} 0" in lines:
38 return True
39 except urllib.error.URLError as e:
40 self.logger.error(e)
41 countdown -= 1
42 return False
43
44
15 def test_debuginfod(self): 45 def test_debuginfod(self):
16 self.write_config( 46 self.write_config(
17 """ 47 """
@@ -25,29 +55,50 @@ CORE_IMAGE_EXTRA_INSTALL += "elfutils"
25 cmd = [ 55 cmd = [
26 os.path.join(native_sysroot, "usr", "bin", "debuginfod"), 56 os.path.join(native_sysroot, "usr", "bin", "debuginfod"),
27 "--verbose", 57 "--verbose",
58 # In-memory database, this is a one-shot test
28 "--database=:memory:", 59 "--database=:memory:",
60 # Don't use all the host cores
61 "--concurrency=8",
62 "--connection-pool=8",
63 # Disable rescanning, this is a one-shot test
64 "--rescan-time=0",
65 "--groom-time=0",
29 get_bb_var("DEPLOY_DIR"), 66 get_bb_var("DEPLOY_DIR"),
30 ] 67 ]
31 for format in get_bb_var("PACKAGE_CLASSES").split(): 68
32 if format == "package_deb": 69 format = get_bb_var("PACKAGE_CLASSES").split()[0]
33 cmd.append("--scan-deb-dir") 70 if format == "package_deb":
34 elif format == "package_ipk": 71 cmd.append("--scan-deb-dir")
35 cmd.append("--scan-deb-dir") 72 elif format == "package_ipk":
36 elif format == "package_rpm": 73 cmd.append("--scan-deb-dir")
37 cmd.append("--scan-rpm-dir") 74 elif format == "package_rpm":
75 cmd.append("--scan-rpm-dir")
76 else:
77 self.fail("Unknown package class %s" % format)
78
38 # Find a free port 79 # Find a free port
39 with socketserver.TCPServer(("localhost", 0), None) as s: 80 with socketserver.TCPServer(("localhost", 0), None) as s:
40 port = s.server_address[1] 81 port = s.server_address[1]
41 cmd.append("--port=%d" % port) 82 cmd.append("--port=%d" % port)
42 83
43 try: 84 try:
44 debuginfod = subprocess.Popen(cmd) 85 # Remove DEBUGINFOD_URLS from the environment so we don't try
86 # looking in the distro debuginfod
87 env = os.environ.copy()
88 if "DEBUGINFOD_URLS" in env:
89 del env["DEBUGINFOD_URLS"]
90
91 self.logger.info(f"Starting server {cmd}")
92 debuginfod = subprocess.Popen(cmd, env=env)
45 93
46 with runqemu("core-image-minimal", runqemuparams="nographic") as qemu: 94 with runqemu("core-image-minimal", runqemuparams="nographic") as qemu:
95 self.assertTrue(self.wait_for_debuginfod(port))
96
47 cmd = ( 97 cmd = (
48 "DEBUGINFOD_URLS=http://%s:%d/ debuginfod-find debuginfo /usr/bin/debuginfod" 98 "DEBUGINFOD_URLS=http://%s:%d/ debuginfod-find debuginfo /usr/bin/debuginfod"
49 % (qemu.server_ip, port) 99 % (qemu.server_ip, port)
50 ) 100 )
101 self.logger.info(f"Starting client {cmd}")
51 status, output = qemu.run_serial(cmd) 102 status, output = qemu.run_serial(cmd)
52 # This should be more comprehensive 103 # This should be more comprehensive
53 self.assertIn("/.cache/debuginfod_client/", output) 104 self.assertIn("/.cache/debuginfod_client/", output)