nm01.sh 2.6 KB

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