Add silent mode to examples Makefiles
[lttng-ust.git] / tests / ust-elf / prog.c
index a39bbc5f02427b7c0c5d4cf03b4c7ddffef30e57..4036563ae44b9fa6dd8a7f32a8c1b63b41b1e23d 100644 (file)
@@ -16,7 +16,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <linux/limits.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #define NUM_ARCH 4
 #define NUM_TESTS_PER_ARCH 11
-#define NUM_TESTS (NUM_ARCH * NUM_TESTS_PER_ARCH) + 1
+#define NUM_TESTS_PIC 3
+#define NUM_TESTS (NUM_ARCH * NUM_TESTS_PER_ARCH) + NUM_TESTS_PIC + 1
 
 /*
  * 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_MEMSZ 5732
+#define X86_64_MEMSZ 2099376
+#define ARMEB_MEMSZ 34196
+#define AARCH64_BE_MEMSZ 67632
 
 #define X86_CRC 0x1531f73c
 #define X86_64_CRC 0xa048a98f
 #define BUILD_ID_LEN 20
 #define DBG_FILE "main.elf.debug"
 
+static const 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
+};
+static const 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
+};
+static const 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
+};
+static const 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
+};
+
 static
 void test_elf(const char *test_dir, const char *arch, uint64_t exp_memsz,
-               uint8_t *exp_build_id, uint32_t exp_crc)
+               const uint8_t *exp_build_id, uint32_t exp_crc)
 {
        char path[PATH_MAX];
        struct lttng_ust_elf *elf = NULL;
@@ -86,7 +104,7 @@ void test_elf(const char *test_dir, const char *arch, uint64_t exp_memsz,
                                        &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,
+       ok(dbg_file && strcmp(dbg_file, DBG_FILE) == 0,
                "debug link filename - expected: %s, got: %s",
                DBG_FILE, dbg_file);
        ok(crc == exp_crc,
@@ -98,24 +116,37 @@ void test_elf(const char *test_dir, const char *arch, uint64_t exp_memsz,
        lttng_ust_elf_destroy(elf);
 }
 
+static
+void test_pic(const char *test_dir)
+{
+       char exec_path[PATH_MAX];
+       char pie_path[PATH_MAX];
+       char pic_path[PATH_MAX];
+       struct lttng_ust_elf *elf = NULL;
+       uint8_t is_pic;
+
+       snprintf(exec_path, PATH_MAX, "%s/data/pic/hello.exec", test_dir);
+       snprintf(pie_path, PATH_MAX, "%s/data/pic/hello.pie", test_dir);
+       snprintf(pic_path, PATH_MAX, "%s/data/pic/hello.pic", test_dir);
+
+       elf = lttng_ust_elf_create(exec_path);
+       is_pic = lttng_ust_elf_is_pic(elf);
+       ok(is_pic == 0, "hello.exec is not PIC");
+       lttng_ust_elf_destroy(elf);
+
+       elf = lttng_ust_elf_create(pie_path);
+       is_pic = lttng_ust_elf_is_pic(elf);
+       ok(is_pic == 1, "hello.pie is PIC");
+       lttng_ust_elf_destroy(elf);
+
+       elf = lttng_ust_elf_create(pic_path);
+       is_pic = lttng_ust_elf_is_pic(elf);
+       ok(is_pic == 1, "hello.pic is PIC");
+       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;
 
        plan_tests(NUM_TESTS);
@@ -127,11 +158,12 @@ int main(int argc, char **argv)
                test_dir = argv[1];
        }
 
-       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,
+       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);
+       test_pic(test_dir);
 
        return EXIT_SUCCESS;
 }
This page took 0.024215 seconds and 4 git commands to generate.