1f08c3bdfSopenharmony_ci#!/bin/sh 2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later 3f08c3bdfSopenharmony_ci# Copyright (c) International Business Machines Corp., 2000 4f08c3bdfSopenharmony_ci# Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> 5f08c3bdfSopenharmony_ci# Author: Robbie Williamson <robbiew@us.ibm.com> 6f08c3bdfSopenharmony_ci# 7f08c3bdfSopenharmony_ci# Tests the basic functionality of the `nm` command. 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ciNM=${NM:=nm} 10f08c3bdfSopenharmony_ci 11f08c3bdfSopenharmony_ciTST_CNT=7 12f08c3bdfSopenharmony_ciTST_TESTFUNC=test 13f08c3bdfSopenharmony_ciTST_SETUP=setup 14f08c3bdfSopenharmony_ciTST_NEEDS_TMPDIR=1 15f08c3bdfSopenharmony_ciTST_NEEDS_CMDS="$NM" 16f08c3bdfSopenharmony_ci 17f08c3bdfSopenharmony_cisetup() 18f08c3bdfSopenharmony_ci{ 19f08c3bdfSopenharmony_ci ROD cp "$TST_DATAROOT/lib.a" "." 20f08c3bdfSopenharmony_ci ROD mkdir "dir" 21f08c3bdfSopenharmony_ci ROD cp "$TST_DATAROOT/lib.a" "dir/" 22f08c3bdfSopenharmony_ci} 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_citest1() 25f08c3bdfSopenharmony_ci{ 26f08c3bdfSopenharmony_ci EXPECT_PASS $NM -f posix -A "lib.a" \> nm.out 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_ci if grep -q "lib.a\[f2.o\]\:" nm.out; then 29f08c3bdfSopenharmony_ci tst_res TPASS "Got correct listing" 30f08c3bdfSopenharmony_ci else 31f08c3bdfSopenharmony_ci tst_res TFAIL "Got incorrect listing" 32f08c3bdfSopenharmony_ci cat nm.out 33f08c3bdfSopenharmony_ci fi 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_ci EXPECT_PASS $NM -f posix -A "dir/lib.a" \> nm.out 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_ci if grep -q "dir/lib.a\[f2.o\]\:" nm.out; then 38f08c3bdfSopenharmony_ci tst_res TPASS "Got correct listing" 39f08c3bdfSopenharmony_ci else 40f08c3bdfSopenharmony_ci tst_res TFAIL "Got incorrect listing" 41f08c3bdfSopenharmony_ci cat nm.out 42f08c3bdfSopenharmony_ci fi 43f08c3bdfSopenharmony_ci} 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_citest2() 46f08c3bdfSopenharmony_ci{ 47f08c3bdfSopenharmony_ci EXPECT_PASS $NM -f posix -g $TST_DATAROOT/f1 \> nm.out 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_ci if grep -q "^[^ ]\+ [abdft]" nm.out; then 50f08c3bdfSopenharmony_ci tst_res TFAIL "Got internal symbols with -g" 51f08c3bdfSopenharmony_ci cat nm.out 52f08c3bdfSopenharmony_ci else 53f08c3bdfSopenharmony_ci tst_res TPASS "Got only external symbols with -g" 54f08c3bdfSopenharmony_ci fi 55f08c3bdfSopenharmony_ci} 56f08c3bdfSopenharmony_ci 57f08c3bdfSopenharmony_citest3() 58f08c3bdfSopenharmony_ci{ 59f08c3bdfSopenharmony_ci EXPECT_PASS $NM -f posix -t o $TST_DATAROOT/f1 \> nm.out 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_ci if awk '{print $3}' nm.out | grep -q "[8-9a-f]"; then 62f08c3bdfSopenharmony_ci tst_res TFAIL "Got non-octal symbol values with -f" 63f08c3bdfSopenharmony_ci cat nm.out 64f08c3bdfSopenharmony_ci else 65f08c3bdfSopenharmony_ci tst_res TPASS "Got an octal symbol values with -f" 66f08c3bdfSopenharmony_ci fi 67f08c3bdfSopenharmony_ci} 68f08c3bdfSopenharmony_ci 69f08c3bdfSopenharmony_citest4() 70f08c3bdfSopenharmony_ci{ 71f08c3bdfSopenharmony_ci EXPECT_PASS $NM -f sysv $TST_DATAROOT/f1 \> nm.out 72f08c3bdfSopenharmony_ci 73f08c3bdfSopenharmony_ci if grep -q "Name" nm.out; then 74f08c3bdfSopenharmony_ci tst_res TPASS "Got SysV format with -f sysv" 75f08c3bdfSopenharmony_ci else 76f08c3bdfSopenharmony_ci tst_res TFAIL "Got wrong format with -f sysv" 77f08c3bdfSopenharmony_ci cat nm.out 78f08c3bdfSopenharmony_ci fi 79f08c3bdfSopenharmony_ci} 80f08c3bdfSopenharmony_ci 81f08c3bdfSopenharmony_citest5() 82f08c3bdfSopenharmony_ci{ 83f08c3bdfSopenharmony_ci EXPECT_PASS $NM -f bsd $TST_DATAROOT/f1 \> nm_bsd.out 84f08c3bdfSopenharmony_ci EXPECT_PASS $NM -f posix $TST_DATAROOT/f1 \> nm_posix.out 85f08c3bdfSopenharmony_ci 86f08c3bdfSopenharmony_ci ROD awk '{print gensub(/\y(0+)([0-9a-fA-F]+)\y/, "\\2", "g")}' nm_bsd.out \> trimmed_nm_bsd.out 87f08c3bdfSopenharmony_ci ROD awk '{print gensub(/\y(0+)([0-9a-fA-F]+)\y/, "\\2", "g")}' nm_posix.out \> trimmed_nm_posix.out 88f08c3bdfSopenharmony_ci 89f08c3bdfSopenharmony_ci ROD awk '{print $3 $2 $1}' trimmed_nm_bsd.out \> nm1.out 90f08c3bdfSopenharmony_ci ROD awk '{print $1 $2 $3}' trimmed_nm_posix.out \> nm2.out 91f08c3bdfSopenharmony_ci 92f08c3bdfSopenharmony_ci if diff nm1.out nm2.out > /dev/null; then 93f08c3bdfSopenharmony_ci tst_res TPASS "Got BSD format with -f bsd" 94f08c3bdfSopenharmony_ci else 95f08c3bdfSopenharmony_ci tst_res TFAIL "Got wrong format with -f bsd" 96f08c3bdfSopenharmony_ci cat nm_bsd.out 97f08c3bdfSopenharmony_ci fi 98f08c3bdfSopenharmony_ci} 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_citest6() 101f08c3bdfSopenharmony_ci{ 102f08c3bdfSopenharmony_ci EXPECT_PASS $NM -f sysv -u $TST_DATAROOT/f1 \> nm.out 103f08c3bdfSopenharmony_ci 104f08c3bdfSopenharmony_ci if grep -q "Undefined symbols from" nm.out; then 105f08c3bdfSopenharmony_ci tst_res TPASS "Got undefined symbols with -u" 106f08c3bdfSopenharmony_ci else 107f08c3bdfSopenharmony_ci tst_res TFAIL "Haven't got undefined symbols with -u" 108f08c3bdfSopenharmony_ci cat nm.out 109f08c3bdfSopenharmony_ci fi 110f08c3bdfSopenharmony_ci} 111f08c3bdfSopenharmony_ci 112f08c3bdfSopenharmony_citest7() 113f08c3bdfSopenharmony_ci{ 114f08c3bdfSopenharmony_ci EXPECT_PASS $NM -s $TST_DATAROOT/lib.a \> nm.out 115f08c3bdfSopenharmony_ci 116f08c3bdfSopenharmony_ci if grep -q "index" nm.out; then 117f08c3bdfSopenharmony_ci tst_res TPASS "Got index with -s" 118f08c3bdfSopenharmony_ci else 119f08c3bdfSopenharmony_ci tst_res TFAIL "Haven't got index with -s" 120f08c3bdfSopenharmony_ci fi 121f08c3bdfSopenharmony_ci} 122f08c3bdfSopenharmony_ci 123f08c3bdfSopenharmony_ci. tst_test.sh 124f08c3bdfSopenharmony_citst_run 125