PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/usdt/tst.noreapring.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 124 lines | 77 code | 17 blank | 30 comment | 7 complexity | 3694b2ed58a1621c075948262ea7bdae MD5 | raw file
  1. #
  2. # CDDL HEADER START
  3. #
  4. # The contents of this file are subject to the terms of the
  5. # Common Development and Distribution License (the "License").
  6. # You may not use this file except in compliance with the License.
  7. #
  8. # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  9. # or http://www.opensolaris.org/os/licensing.
  10. # See the License for the specific language governing permissions
  11. # and limitations under the License.
  12. #
  13. # When distributing Covered Code, include this CDDL HEADER in each
  14. # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15. # If applicable, add the following below this CDDL HEADER, with the
  16. # fields enclosed by brackets "[]" replaced with your own identifying
  17. # information: Portions Copyright [yyyy] [name of copyright owner]
  18. #
  19. # CDDL HEADER END
  20. #
  21. #
  22. # Copyright (c) 2011, Joyent, Inc. All rights reserved.
  23. #
  24. if [ $# != 1 ]; then
  25. echo expected one argument: '<'dtrace-path'>'
  26. exit 2
  27. fi
  28. dtrace=$1
  29. DIR=/var/tmp/dtest.$$
  30. mkdir $DIR
  31. cd $DIR
  32. cat > test.c <<EOF
  33. #include <unistd.h>
  34. #include <sys/sdt.h>
  35. int
  36. main(int argc, char **argv)
  37. {
  38. DTRACE_PROBE(test_prov, probe1);
  39. }
  40. EOF
  41. cat > prov.d <<EOF
  42. provider test_prov {
  43. probe probe1();
  44. };
  45. EOF
  46. cc -c test.c
  47. if [ $? -ne 0 ]; then
  48. print -u2 "failed to compile test.c"
  49. exit 1
  50. fi
  51. $dtrace -G -s prov.d test.o
  52. if [ $? -ne 0 ]; then
  53. print -u2 "failed to create DOF"
  54. exit 1
  55. fi
  56. cc -o test test.o prov.o
  57. if [ $? -ne 0 ]; then
  58. print -u2 "failed to link final executable"
  59. exit 1
  60. fi
  61. script()
  62. {
  63. $dtrace -Zwqs /dev/stdin <<EOF
  64. test_prov*:::
  65. {
  66. probeid = id;
  67. }
  68. tick-1sec
  69. /probeid == 0/
  70. {
  71. printf("launching test\n");
  72. system("./test");
  73. }
  74. tick-1sec
  75. /probeid != 0/
  76. {
  77. printf("attempting re-enabling\n");
  78. system("dtrace -e -x errtags -i %d", probeid);
  79. attempts++;
  80. }
  81. tick-1sec
  82. /attempts > 10/
  83. {
  84. exit(0);
  85. }
  86. EOF
  87. }
  88. $dtrace -x bufpolicy=ring -ZwqP test_prov\* > /dev/null 2>&1 &
  89. background=$!
  90. echo launched ring buffered enabling as pid $background
  91. script 2>&1 | tee test.out
  92. #
  93. # It should be true that our probe was not reaped after the provider was made
  94. # defunct: the active ring buffer in the earlier enabling prevents reaping of
  95. # any of the earlier enabling's ECBs.
  96. #
  97. status=0
  98. if grep D_PDESC_INVAL test.out 2> /dev/null 1>&2 ; then
  99. status=1
  100. else
  101. grep D_PROC_GRAB test.out 2> /dev/null 1>&2
  102. status=$?
  103. fi
  104. kill $background
  105. cd /
  106. rm -rf $DIR
  107. exit $status