PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 128 lines | 79 code | 19 blank | 30 comment | 7 complexity | 023a14bd9bb87f879aeb983f378eee2e 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. BEGIN
  65. {
  66. spec = speculation();
  67. speculate(spec);
  68. printf("this is speculative!\n");
  69. }
  70. test_prov*:::
  71. {
  72. probeid = id;
  73. }
  74. tick-1sec
  75. /probeid == 0/
  76. {
  77. printf("launching test\n");
  78. system("./test");
  79. }
  80. tick-1sec
  81. /probeid != 0/
  82. {
  83. printf("attempting re-enabling\n");
  84. system("dtrace -e -x errtags -i %d", probeid);
  85. attempts++;
  86. }
  87. tick-1sec
  88. /attempts > 10/
  89. {
  90. exit(0);
  91. }
  92. EOF
  93. }
  94. script 2>&1 | tee test.out
  95. #
  96. # It should be true that our probe was not reaped after the provider was made
  97. # defunct: the speculative tracing action prevents reaping of any ECB in the
  98. # enabling.
  99. #
  100. status=0
  101. if grep D_PDESC_INVAL test.out 2> /dev/null 1>&2 ; then
  102. status=1
  103. else
  104. grep D_PROC_GRAB test.out 2> /dev/null 1>&2
  105. status=$?
  106. fi
  107. cd /
  108. rm -rf $DIR
  109. exit $status