From 22609c7a82c5c8ebc07c19cade9b4d6ff61bd0d0 Mon Sep 17 00:00:00 2001 From: Antoine Busque Date: Thu, 30 Jul 2015 16:37:04 -0400 Subject: [PATCH] Add unit tests for lttng_ust_elf This adds unit tests for UST's ELF parser. Also included are test ELF files for multiple architectures (x86, x86_64, armeb, aarch64_be). The procedure to generate these test files is described in `tests/ust-elf/README.md`. Signed-off-by: Antoine Busque Signed-off-by: Mathieu Desnoyers --- .gitignore | 1 + configure.ac | 1 + tests/Makefile.am | 2 +- tests/unit_tests | 1 + tests/ust-elf/Makefile.am | 24 ++++ tests/ust-elf/README.md | 42 ++++++ tests/ust-elf/data/aarch64_be/main.elf | Bin 0 -> 7115 bytes tests/ust-elf/data/aarch64_be/main.elf.debug | Bin 0 -> 7278 bytes tests/ust-elf/data/armeb/main.elf | Bin 0 -> 5273 bytes tests/ust-elf/data/armeb/main.elf.debug | Bin 0 -> 5666 bytes tests/ust-elf/data/main.c | 6 + tests/ust-elf/data/x86/main.elf | Bin 0 -> 4772 bytes tests/ust-elf/data/x86/main.elf.debug | Bin 0 -> 4328 bytes tests/ust-elf/data/x86_64/main.elf | Bin 0 -> 6536 bytes tests/ust-elf/data/x86_64/main.elf.debug | Bin 0 -> 4952 bytes tests/ust-elf/prog.c | 130 +++++++++++++++++++ tests/ust-elf/test_ust_elf | 4 + 17 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 tests/ust-elf/Makefile.am create mode 100644 tests/ust-elf/README.md create mode 100644 tests/ust-elf/data/aarch64_be/main.elf create mode 100755 tests/ust-elf/data/aarch64_be/main.elf.debug create mode 100644 tests/ust-elf/data/armeb/main.elf create mode 100755 tests/ust-elf/data/armeb/main.elf.debug create mode 100644 tests/ust-elf/data/main.c create mode 100644 tests/ust-elf/data/x86/main.elf create mode 100755 tests/ust-elf/data/x86/main.elf.debug create mode 100644 tests/ust-elf/data/x86_64/main.elf create mode 100755 tests/ust-elf/data/x86_64/main.elf.debug create mode 100644 tests/ust-elf/prog.c create mode 100755 tests/ust-elf/test_ust_elf diff --git a/.gitignore b/.gitignore index 1039b1a0..b1f985b8 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ tests/trace_event/trace_event_test tests/tracepoint/benchmark/tracepoint_benchmark tests/tracepoint/tracepoint_test tests/snprintf/prog +tests/ust-elf/prog tests/benchmark/bench1 tests/benchmark/bench2 diff --git a/configure.ac b/configure.ac index ede01952..cd92e192 100644 --- a/configure.ac +++ b/configure.ac @@ -402,6 +402,7 @@ AC_CONFIG_FILES([ tests/hello.cxx/Makefile tests/same_line_tracepoint/Makefile tests/snprintf/Makefile + tests/ust-elf/Makefile tests/benchmark/Makefile tests/utils/Makefile lttng-ust.pc diff --git a/tests/Makefile.am b/tests/Makefile.am index 30b0e9a0..3d7ceeb9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = utils hello same_line_tracepoint snprintf benchmark +SUBDIRS = utils hello same_line_tracepoint snprintf benchmark ust-elf if CXX_WORKS SUBDIRS += hello.cxx diff --git a/tests/unit_tests b/tests/unit_tests index 91101383..4d69789b 100644 --- a/tests/unit_tests +++ b/tests/unit_tests @@ -1 +1,2 @@ snprintf/test_snprintf +ust-elf/test_ust_elf diff --git a/tests/ust-elf/Makefile.am b/tests/ust-elf/Makefile.am new file mode 100644 index 00000000..3cb54423 --- /dev/null +++ b/tests/ust-elf/Makefile.am @@ -0,0 +1,24 @@ +AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/tests/utils + +noinst_PROGRAMS = prog +prog_SOURCES = prog.c +prog_LDADD = $(top_builddir)/liblttng-ust/liblttng-ust.la \ + $(top_builddir)/tests/utils/libtap.a + +SCRIPT_LIST = test_ust_elf + +dist_noinst_SCRIPTS = $(SCRIPT_LIST) + +all-local: + @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ + for script in $(SCRIPT_LIST); do \ + cp -f $(srcdir)/$$script $(builddir); \ + done; \ + fi + +clean-local: + @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ + for script in $(SCRIPT_LIST); do \ + rm -f $(builddir)/$$script; \ + done; \ + fi diff --git a/tests/ust-elf/README.md b/tests/ust-elf/README.md new file mode 100644 index 00000000..787af8c7 --- /dev/null +++ b/tests/ust-elf/README.md @@ -0,0 +1,42 @@ +lttng_ust_elf unit tests +======================== + +This is a series of unit tests for LTTng UST's ELF parser. The parser +is used to retrieve memory size, build ID, and debug link information +from ELF objects (standalone executable or shared object) for base +address statedump or dl events. + +The parser should technically be able to read ELF files from any 32- +or 64-bit architecture, little- or big- endian. + +However, to restrict the total amount of testing done, only 4 +architectures representing all combinations of bitness and endianness +are currently tested: + +* x86 +* x86_64 +* armeb +* aarch64_be + +For each architecture, there is a corresponding subdirectory under +`data`, and each of these directories contains exactly 2 files, +`main.elf` and `main.elf.debug`. + +The ELF files are generated from the trivial `main.c` program found in +`data/`, using GNU toolchains. The program contains a static array in +order to ensure the creation of a `.bss` section in the ELF file, +which is one of the multiple factors leading to different file and +in-memory size. + +The program is compiled with `gcc -g main.c -o main.elf`. On certain +architectures, it is necessary to explicitly specify the +`-Wl,--build-id=sha1` flags to include a build ID in the resulting +executable. + +The debug information bundled in `main.elf` is then copied into +`main.elf.debug` and stripped, and a debug link pointing to this file +is added to the executable. The commands used are as follow: + + $ objcopy --only-keep-debug main.elf main.elf.debug + $ strip -g main.elf + $ objcopy --add-gnu-debuglink=main.elf.debug main.elf diff --git a/tests/ust-elf/data/aarch64_be/main.elf b/tests/ust-elf/data/aarch64_be/main.elf new file mode 100644 index 0000000000000000000000000000000000000000..c30502e84ac8daecd5c2304de10ceeb081d33712 GIT binary patch literal 7115 zcmcIpZ)_Y#6@R;H$8J)}Cb^JEgn}ZA@5>fT-c)RB`E$4H?Fjn{V@`{@0N z?#>~pKhzWz0qTcXOP(4t3rsCXWzcx`#bMuW@pFG>>1eWx(-B_3qQtZ27K?P!F{IpoY2&VKIi}+*2Bk; zUxuxn<%rSc$0#`8(0D|l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;%{~8{>hcy2kl27j!jmtRm=)IwF zj4k-z)#s29!5{ftH7d6SpbEg@zXwu-&TrWPxO{&X{+j`Rr{vRltNHgSd{ZJCho3S? z4LTn+KBe%364Cg6Q>HeI`z~smHQ@Lyyd?pi|2rAIfWOBObrW#9x6l|i02e=ELm;=v=jr!MsXv!7qt7dkOd@IDW*Jof|e@^3l58&i%AIV5j69wqt{T z%iw<=_+{ra#?>Cd^PHa={A&;lDxNE^DIDIr_IIl}$!OU>2b|(o?x*Ore+7$Ew!eQg z@af!;y$LwkG0uPcZ{SbKxncjK+>T?(U>GYMhrs`mRftzLwk3&kInUZ&q`s zjh6GWF<;ZpPqyLT0Q+=4U)F|(?g;Bium(4w;*t-qoa^x*TN`8&sCRo|vsIgMXQma< zN(XSe7}msHVayJ++1s_2W`2^nU}~M=%^+O3>I=^-j(c!>8AfT{_mkG@+$?Vfa7mjO zVoiHqgWJ2odJV24>*+=+=7Ln1LEUw+nwzb+k}QO=T7Iv`pAGzHcqjTl4;SHZNtR}V zP6y`3`RRr8e0k}@3g@gHBtbV!;r5khectND5nNK1K%BQ@-tEOrzsK8IoTS_ztTVXe zTQAPvl&0Rd~Uw6%+H-TabaD;&ff@(^ literal 0 HcmV?d00001 diff --git a/tests/ust-elf/data/armeb/main.elf b/tests/ust-elf/data/armeb/main.elf new file mode 100644 index 0000000000000000000000000000000000000000..10e470c743b8d82b96f7241ba3854486b7c790c9 GIT binary patch literal 5273 zcmb7IU2I%O6`s3ZI~(%DCUH_HbPy>lNdPOkoQ;@y7Q z43GU72jc%Gd$3nGNZPBJpR*ley0QcIpR%g#@O_*<_X;;tD*Hl8w#bU_mVH@pb49dF z6iP+YBE_lUq5c8coxoP<^@QM=-6O77?8@c1F8bU}ES%N_!2Kw(Z_WXfmw;JTv7`eZ z#Z!?7LOgT-b~RFu*TVIsTDW$tw!8lB!w7u6w|4EfV(sehBK4pDBUry1Xn${gc}1)* z*Tjc!M#HPiv0e3eEL@KZjCChkkKaKlcGj1YJ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sEGotc0ruiW>Yl*2M z)MfeFpHR}6jlUthF9yCFh|o8I5fe544$+krU9K2+^LhCl&wX8<=ZAyS1EX?y=v-P# zk@d>nM6QB=4$?2k@qDR>_vNlv=O zEL@O7XEAFwSCrEg59@v6J=crbi)b|KB~Srtx+?TXqth4UsM+v=yj!VYx242NZG;(u OEd!uFLv3(X&H8T{b~}{- literal 0 HcmV?d00001 diff --git a/tests/ust-elf/data/armeb/main.elf.debug b/tests/ust-elf/data/armeb/main.elf.debug new file mode 100755 index 0000000000000000000000000000000000000000..0971af30c23b7a4e516838206b833cb8fcf7a536 GIT binary patch literal 5666 zcmb_gU5H#s6|Q@`Cz&|Om}F*6vKzI7Q8#FJPsTBu>~1tOlSyX6OyVZJ4=!0Nx4Un5 z-?h7Md++Tyvn*t$GeXcPSqLnM;15ApQCOdhFYAME`XIuBAS?KT5J4det1k-c_tj7L zopz7~Jy7@7SLdr!r%qL!?z%S?md`n^Bl_Zs$5BT^?>^o$LX0FM!gW#0iBaf|iX$DR zcWw)@+0;e#9>p_j$`0Lk9sOBoUyU(h^ci5ZZGZkc<+ z+2?$Cd}1s!{@D0FXaA192e5tx=hKHW<4=w~HMTUt#xnmMk2QiDI zVr=YFV;NW)ah#OB2O03}BSw98HMl)Wqjq=bz(ygabhvisRR6K_v*|VlzqF z^86hSu0k(#1o?B1?@sb1zLWyfWTNq~8r&!`k{$M-LHwZ2i%G}BMpehOt zFK&oJb*&9s`kh3gK+bhPii5Dd1xV;3ze&EXbef4M1nmIN#9zg;1^`v47N&qrU+`Ch z>Z&OC4Oxr4mapm3iz07L({25Q3arDj*9s~aHH0;7r5wkiPzhTtA3Ijr^pYeB%3bUQ zaQt$&4jW#(K7c{H7WP%;a^zpP2x|i$bSLAG1_+(r7Vqx)7-&2s*lx^~%$X`r+TLp8 z0elFBXNo-JH0CyuL$Si#LphFOc@6MTkkJQXd1uiyib8wHz0AM=!6WxViuan~ok1Ig zzLCS6cp1goduVu1qs@w)$8%^fyxzwRkJt+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TW1gs8GCTFBc8w9wkNkEJBcPk4XPVu9h&Xph zmoZ-7w7dO=+cjR&k7DBvuM6Vjpz9~T=bS!s`XoFbLNbilS^PDKsnMQf5!)N~dV3gB zK!%GwK+SWcG255c&u^Kn3!7MTwgGJ)7~_fAeCERX`Fahkf+bGeC=qjZ=im~2&&byJN1p4 z;cuzJa=Aglp<+Znduw1i*FZrQ%ey#S%oA75rTjbBx^5ifBO8OA>4|d7`qd9^IGrQC ze*ag&h{@o^YnlFz#{FiDQvpon7)oX*^3vbCFjUZ1$ugbD33Mord9efDgGxfJyiK%q zUgk^wPOgmc$mQ=v9F9XH}@_6Z+{^7!9J zMS0&thw}J4gS?+83AOTml=E!V%t!oRrZ&>G{j&m(dF}0ZzbWvTAK#Amy8@4Sk-Rt1 zr^0!;{y*k5*H=Y8Im{oqe=hKtN68yMXY&45;4xp4$9Yu9q5K2Ne$LB0Gd?elGnId% zWLxhD&-sDOl$NwnCsD9g`7S_30cy3~iH5dm{slmC2=D$e-Ucp&e+X}NjQ36O&K$yf zH0S9)eh=OYV?0oh`?E7q(-j=hHVwIGlQmq7#Q*>R literal 0 HcmV?d00001 diff --git a/tests/ust-elf/data/x86_64/main.elf b/tests/ust-elf/data/x86_64/main.elf new file mode 100644 index 0000000000000000000000000000000000000000..341e4a225c83417e39af6d8a3c50a3be332865a6 GIT binary patch literal 6536 zcmcIp3v83u6~4BU;F91x25SneSY43PZgB&HEM3|7ofm(Qc??3QsSQ6)>?B_Oi2Ps) zLR!|e9acvhY14$JX+qjVOxiRyX$)=BnvANTJ*0Hfq-rmNyYol{m-#~ z|1lHNw1fPgd%p9y=f3X^UmA=Ic|9H_oa(EP!9|-Nr-VSll?rN^{75y& z`niT98W-Nld2~xY>_;NGoMOLI>?eGg0)vE0`>1X7+sN@YdJRY<8^qLr{#Ll|3t;=N zL%@KTeS?{yS@7^`pteSkJacld-O3B3+p2n(6K7>e&{` zWkOqZ{$xi@+_m?R_K^MvLZZ6Y;zwgi`sT0v^m50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cf2^gir{vR_o&-=}2Xsm52A_or&SQOQ1CjW?-j<16zC z18>18C+kd{&Ut9=ND|h=reQ#xoa)4y}P}?XM4I|6E*6uQhxv*3&t!8}v@oM^I!q_y`FJeU^Vrr;;+0gx$f9$~K6NadB-vSIpHs0yDm4oihh)+5 zR%L2gLkGfp2Cc!p14!1+T*_6(F=Y*Wes6fsa6haZ8vTY-)~?9DzHr3aH#Br`aKsu3 z_eBONoPOqw=L$MUWetz)!5Js5AKBAS-7yj!OU4x)iT3kPS#fF%S}0UpKvWHgt< z5Ly<}mu{nW)ohjSDd!~nAIh|2U@DgP1?4p$fq0{k`?3w%wo)ce_W+zKVqQMix9@Y6cb4pX)9mj)>D=RAL`-Uz^po5(7F_kiL{p24e;u;Zf06TFWdCPK=^*hJ z=$j}w{pH>=z#S&3-`Z89%`mQJ^;hcUSpdKF0&%ws*_FgKx9LU)}*H?$O`AuUG1q_shaP`u`Pm zld0q{_kQ`i?=p`+hbzxtnFnvfmrTT8?tN3-PCVEXR~$z3qwe`EjqUBO+Vu3OfQ)BiRv-1EE+9)yzahSDFhFOpfU`p?p&2DQ0@ HyX*fCq1gbv literal 0 HcmV?d00001 diff --git a/tests/ust-elf/data/x86_64/main.elf.debug b/tests/ust-elf/data/x86_64/main.elf.debug new file mode 100755 index 0000000000000000000000000000000000000000..275f2cae9de3ae45f8f76c887a7e0ddc4c200851 GIT binary patch literal 4952 zcmbVPU1%It6h1qXrm3+uNvlR1Ww8~i(jkqlRw**c=BFw7sqHE#;>~1dl3m@OFf&^k z5e!wdzDPhHiuh3UrEgUq`l!(dDJW9Vhaw0n*q6Ro@Iid3=iIp`d-v|O7BB2Q=Y02k z=brmBGiTqJn3;5PIpF5NGeFjc>q{u>0j~B+Q(=dp2Yh%Cc0)HJTkz-05t5n4azlk? z*`xeilwG7d3UK^PVVPMlq$FoZlICkQU#Xc~Q1M=;#AM6Mo_GYUDSWMaLEf!#3Y z19=INsq@Y$9!u$j-4&G}uaDM7zabTG$nnu4+b03zvTsSb7lanh%${cS!S(LPosDRym}*z zywS1g{b{hQtmS&sTWnUU;r>bp9$DoeDT5cT)-hft(>NPB6~#%VQExK@j>Sk|oVDV+VBLz}4d#1=0=aMxlzSFrOucjAURbf>gK*A@ z-v<}0`2BiVspqiof*Uu@0eZjL@STX~@NHnOE04GX+u;x6ybdXRxXVYa)sCV{{woIl zGU7RCo5*KI}n!0QbRH_m)3zk0YL!vD&+NiFe+g7ZLA+ z!H)YAAUoU7F*-XTCg#R5=WGG2w{b!c<1fsO&Q2H5OB+ejAWlI{&CHLD&WQQR$&(XB zQ5+qcnV@jh%3?{BlBP@*#B_01wDzSqTcBMj28-1Q==&>FutTrv zni0gYQ{sd=%tAFt59_Cy>${Ok?>>HCfa9ZuO#wrhwb|n} zZ)zE@d;NEuk4*ocf>-jG@J|eJLSDX2huioa+ z(D`eQk4TGuR9aa_YiItT!k^=;W&S}Gmj(0KzGU#Z?q&X;?5HH4AHy4{5JvwEsd2r+|G!Ot)BX-QI-l$4 z+vQ(1_*|FXF8^nP&viNTuNddg`SU%vX7IUwXFmI*n`~^eypAa8ynkHhGk;%3+w7Ug zlFmoxbG^lU&XWT$k8P?mbw1ZG%s2gw?Ew1YK-e$`RFdz{Lk7-#mi;)+Yu8=Rs0-c0 rj%v^_<=lMtb^f{vI;bA(2XN5CAFqesYxI2D=D(mG+{cXI=KTKvEP&39 literal 0 HcmV?d00001 diff --git a/tests/ust-elf/prog.c b/tests/ust-elf/prog.c new file mode 100644 index 00000000..bc36b321 --- /dev/null +++ b/tests/ust-elf/prog.c @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2015 Antoine Busque + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +#include +#include "tap.h" + +#define NUM_ARCH 4 +#define NUM_TESTS_PER_ARCH 11 +#define NUM_TESTS (NUM_ARCH * NUM_TESTS_PER_ARCH) + +/* + * Expected memsz were computed using libelf, build ID and debug link + * were determined through readelf. + */ +#define X86_MEMSZ 8192 +#define X86_64_MEMSZ 4194304 +#define ARMEB_MEMSZ 65536 +#define AARCH64_BE_MEMSZ 131072 + +#define X86_CRC 0x1531f73c +#define X86_64_CRC 0xa048a98f +#define ARMEB_CRC 0x9d40261b +#define AARCH64_BE_CRC 0x2b8cedce + +#define BUILD_ID_LEN 20 +#define DBG_FILE "main.elf.debug" + +static +void test_elf(const char *test_dir, const char *arch, uint64_t exp_memsz, + uint8_t *exp_build_id, uint32_t exp_crc) +{ + char path[PATH_MAX]; + struct lttng_ust_elf *elf = NULL; + int ret = 0; + uint64_t memsz = 0; + int has_build_id = 0; + uint8_t *build_id = NULL; + size_t build_id_len = 0; + int has_debug_link = 0; + char *dbg_file = NULL; + uint32_t crc = 0; + + diag("Testing %s support", arch); + + snprintf(path, PATH_MAX, "%s/data/%s/main.elf", test_dir, arch); + elf = lttng_ust_elf_create(path); + ok(elf != NULL, "lttng_ust_elf_create"); + + ret = lttng_ust_elf_get_memsz(elf, &memsz); + ok(ret == 0, "lttng_ust_elf_get_memsz returned successfully"); + ok(memsz == exp_memsz, + "memsz - expected: %lu, got: %lu", + exp_memsz, memsz); + + ret = lttng_ust_elf_get_build_id(elf, &build_id, &build_id_len, + &has_build_id); + ok(ret == 0, "lttng_ust_elf_get_build_id returned successfully"); + ok(has_build_id == 1, "build id marked as found"); + ok(build_id_len == BUILD_ID_LEN, + "build_id_len - expected: %u, got: %u", + BUILD_ID_LEN, build_id_len); + ok(memcmp(build_id, exp_build_id, build_id_len) == 0, + "build_id has expected value"); + + ret = lttng_ust_elf_get_debug_link(elf, &dbg_file, &crc, + &has_debug_link); + ok(ret == 0, "lttng_ust_elf_get_debug_link returned successfully"); + ok(has_debug_link == 1, "debug link marked as found"); + ok(strcmp(dbg_file, DBG_FILE) == 0, + "debug link filename - expected: %s, got: %s", + DBG_FILE, dbg_file); + ok(crc == exp_crc, + "debug link crc - expected: %#x, got: %#x", + exp_crc, crc); + + free(build_id); + free(dbg_file); + lttng_ust_elf_destroy(elf); +} + +int main(int argc, char **argv) +{ + uint8_t X86_BUILD_ID[BUILD_ID_LEN] = { + 0x27, 0x79, 0x2a, 0xe7, 0xaa, 0xef, 0x72, 0x5c, 0x9c, 0x52, + 0x80, 0xec, 0x1e, 0x18, 0xd8, 0x09, 0x02, 0xba, 0xbc, 0x82 + }; + uint8_t X86_64_BUILD_ID[BUILD_ID_LEN] = { + 0x0f, 0x87, 0xb2, 0xe2, 0x24, 0x9c, 0xe1, 0xc2, 0x24, 0xb1, + 0xf8, 0xb6, 0x65, 0x83, 0xa3, 0xc1, 0xcb, 0x30, 0x5c, 0x63 + }; + uint8_t ARMEB_BUILD_ID[BUILD_ID_LEN] = { + 0x60, 0x5d, 0x26, 0xa0, 0x0e, 0x30, 0xa4, 0x29, 0xf4, 0xf1, + 0x85, 0x53, 0xda, 0x90, 0x68, 0xe1, 0xf5, 0x67, 0xbe, 0x42 + }; + uint8_t AARCH64_BE_BUILD_ID[BUILD_ID_LEN] = { + 0xb9, 0x0a, 0xa0, 0xed, 0xd1, 0x41, 0x42, 0xc3, 0x34, 0x85, + 0xfa, 0x27, 0x2e, 0xa9, 0x2f, 0xd2, 0xe4, 0xf7, 0xb6, 0x60 + }; + const char *TEST_DIR = argv[1]; + + plan_tests(NUM_TESTS); + + test_elf(TEST_DIR, "x86", X86_MEMSZ, X86_BUILD_ID, X86_CRC); + test_elf(TEST_DIR, "x86_64", X86_64_MEMSZ, X86_64_BUILD_ID, X86_64_CRC); + test_elf(TEST_DIR, "armeb", ARMEB_MEMSZ, ARMEB_BUILD_ID, ARMEB_CRC); + test_elf(TEST_DIR, "aarch64_be", AARCH64_BE_MEMSZ, AARCH64_BE_BUILD_ID, + AARCH64_BE_CRC); + + return 0; +} diff --git a/tests/ust-elf/test_ust_elf b/tests/ust-elf/test_ust_elf new file mode 100755 index 00000000..cb7c7a94 --- /dev/null +++ b/tests/ust-elf/test_ust_elf @@ -0,0 +1,4 @@ +#!/bin/bash + +TEST_DIR=$(dirname $0) +./${TEST_DIR}/prog $TEST_DIR -- 2.34.1