(self)
| 34 | |
| 35 | class TestSymbolChecks(unittest.TestCase): |
| 36 | def test_ELF(self): |
| 37 | source = 'test1.c' |
| 38 | executable = 'test1' |
| 39 | cc = determine_wellknown_cmd('CC', 'gcc') |
| 40 | |
| 41 | # there's no way to do this test for RISC-V at the moment; we build for |
| 42 | # RISC-V in a glibc 2.27 envinonment and we allow all symbols from 2.27. |
| 43 | if 'riscv' in get_machine(cc): |
| 44 | self.skipTest("test not available for RISC-V") |
| 45 | |
| 46 | # nextup was introduced in GLIBC 2.24, so is newer than our supported |
| 47 | # glibc (2.18), and available in our release build environment (2.24). |
| 48 | with open(source, 'w', encoding="utf8") as f: |
| 49 | f.write(''' |
| 50 | #define _GNU_SOURCE |
| 51 | #include <math.h> |
| 52 | |
| 53 | double nextup(double x); |
| 54 | |
| 55 | int main() |
| 56 | { |
| 57 | nextup(3.14); |
| 58 | return 0; |
| 59 | } |
| 60 | ''') |
| 61 | |
| 62 | self.assertEqual(call_symbol_check(cc, source, executable, ['-lm']), |
| 63 | (1, executable + ': symbol nextup from unsupported version GLIBC_2.24(3)\n' + |
| 64 | executable + ': failed IMPORTED_SYMBOLS')) |
| 65 | |
| 66 | # -lutil is part of the libc6 package so a safe bet that it's installed |
| 67 | # it's also out of context enough that it's unlikely to ever become a real dependency |
| 68 | source = 'test2.c' |
| 69 | executable = 'test2' |
| 70 | with open(source, 'w', encoding="utf8") as f: |
| 71 | f.write(''' |
| 72 | #include <utmp.h> |
| 73 | |
| 74 | int main() |
| 75 | { |
| 76 | login(0); |
| 77 | return 0; |
| 78 | } |
| 79 | ''') |
| 80 | |
| 81 | self.assertEqual(call_symbol_check(cc, source, executable, ['-lutil']), |
| 82 | (1, executable + ': libutil.so.1 is not in ALLOWED_LIBRARIES!\n' + |
| 83 | executable + ': failed LIBRARY_DEPENDENCIES')) |
| 84 | |
| 85 | # finally, check a simple conforming binary |
| 86 | source = 'test3.c' |
| 87 | executable = 'test3' |
| 88 | with open(source, 'w', encoding="utf8") as f: |
| 89 | f.write(''' |
| 90 | #include <stdio.h> |
| 91 | |
| 92 | int main() |
| 93 | { |
nothing calls this directly
no test coverage detected