1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2003-2005 Hewlett-Packard Co
3 Contributed by Paul Pluzhnikov <ppluzhnikov@google.com>
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 /* Verify that register state caches work under all caching policies
25 in a multi-threaded environment with a large number IPs */
27 #define UNW_LOCAL_ONLY
28 #include <libunwind.h>
35 /* ITERS=1000, NTHREAD=10 caught some bugs in the past */
52 if ((n = unw_backtrace (buf, 20)) < 3)
62 if ((n = unw_backtrace (buf, 20)) < 3)
72 if ((n = unw_backtrace (buf, 20)) < 3)
82 if ((n = unw_backtrace (buf, 20)) < 3)
92 if ((n = unw_backtrace (buf, 20)) < 3)
102 if ((n = unw_backtrace (buf, 20)) < 3)
112 if ((n = unw_backtrace (buf, 20)) < 3)
122 if ((n = unw_backtrace (buf, 20)) < 3)
132 if ((n = unw_backtrace (buf, 20)) < 3)
142 if ((n = unw_backtrace (buf, 20)) < 3)
152 if ((n = unw_backtrace (buf, 20)) < 3)
162 if ((n = unw_backtrace (buf, 20)) < 3)
172 if ((n = unw_backtrace (buf, 20)) < 3)
182 if ((n = unw_backtrace (buf, 20)) < 3)
192 if ((n = unw_backtrace (buf, 20)) < 3)
202 if ((n = unw_backtrace (buf, 20)) < 3)
212 if ((n = unw_backtrace (buf, 20)) < 3)
222 if ((n = unw_backtrace (buf, 20)) < 3)
232 if ((n = unw_backtrace (buf, 20)) < 3)
242 if ((n = unw_backtrace (buf, 20)) < 3)
252 if ((n = unw_backtrace (buf, 20)) < 3)
262 if ((n = unw_backtrace (buf, 20)) < 3)
272 if ((n = unw_backtrace (buf, 20)) < 3)
282 if ((n = unw_backtrace (buf, 20)) < 3)
292 if ((n = unw_backtrace (buf, 20)) < 3)
302 if ((n = unw_backtrace (buf, 20)) < 3)
312 if ((n = unw_backtrace (buf, 20)) < 3)
322 if ((n = unw_backtrace (buf, 20)) < 3)
332 if ((n = unw_backtrace (buf, 20)) < 3)
342 if ((n = unw_backtrace (buf, 20)) < 3)
352 if ((n = unw_backtrace (buf, 20)) < 3)
362 if ((n = unw_backtrace (buf, 20)) < 3)
372 if ((n = unw_backtrace (buf, 20)) < 3)
382 if ((n = unw_backtrace (buf, 20)) < 3)
392 if ((n = unw_backtrace (buf, 20)) < 3)
402 if ((n = unw_backtrace (buf, 20)) < 3)
412 if ((n = unw_backtrace (buf, 20)) < 3)
422 if ((n = unw_backtrace (buf, 20)) < 3)
432 if ((n = unw_backtrace (buf, 20)) < 3)
442 if ((n = unw_backtrace (buf, 20)) < 3)
452 if ((n = unw_backtrace (buf, 20)) < 3)
462 if ((n = unw_backtrace (buf, 20)) < 3)
472 if ((n = unw_backtrace (buf, 20)) < 3)
482 if ((n = unw_backtrace (buf, 20)) < 3)
492 if ((n = unw_backtrace (buf, 20)) < 3)
502 if ((n = unw_backtrace (buf, 20)) < 3)
512 if ((n = unw_backtrace (buf, 20)) < 3)
522 if ((n = unw_backtrace (buf, 20)) < 3)
532 if ((n = unw_backtrace (buf, 20)) < 3)
542 if ((n = unw_backtrace (buf, 20)) < 3)
552 if ((n = unw_backtrace (buf, 20)) < 3)
562 if ((n = unw_backtrace (buf, 20)) < 3)
572 if ((n = unw_backtrace (buf, 20)) < 3)
582 if ((n = unw_backtrace (buf, 20)) < 3)
592 if ((n = unw_backtrace (buf, 20)) < 3)
602 if ((n = unw_backtrace (buf, 20)) < 3)
612 if ((n = unw_backtrace (buf, 20)) < 3)
622 if ((n = unw_backtrace (buf, 20)) < 3)
632 if ((n = unw_backtrace (buf, 20)) < 3)
642 if ((n = unw_backtrace (buf, 20)) < 3)
652 if ((n = unw_backtrace (buf, 20)) < 3)
662 if ((n = unw_backtrace (buf, 20)) < 3)
672 if ((n = unw_backtrace (buf, 20)) < 3)
682 if ((n = unw_backtrace (buf, 20)) < 3)
692 if ((n = unw_backtrace (buf, 20)) < 3)
702 if ((n = unw_backtrace (buf, 20)) < 3)
712 if ((n = unw_backtrace (buf, 20)) < 3)
722 if ((n = unw_backtrace (buf, 20)) < 3)
732 if ((n = unw_backtrace (buf, 20)) < 3)
742 if ((n = unw_backtrace (buf, 20)) < 3)
752 if ((n = unw_backtrace (buf, 20)) < 3)
762 if ((n = unw_backtrace (buf, 20)) < 3)
772 if ((n = unw_backtrace (buf, 20)) < 3)
782 if ((n = unw_backtrace (buf, 20)) < 3)
792 if ((n = unw_backtrace (buf, 20)) < 3)
802 if ((n = unw_backtrace (buf, 20)) < 3)
812 if ((n = unw_backtrace (buf, 20)) < 3)
822 if ((n = unw_backtrace (buf, 20)) < 3)
832 if ((n = unw_backtrace (buf, 20)) < 3)
842 if ((n = unw_backtrace (buf, 20)) < 3)
852 if ((n = unw_backtrace (buf, 20)) < 3)
862 if ((n = unw_backtrace (buf, 20)) < 3)
872 if ((n = unw_backtrace (buf, 20)) < 3)
882 if ((n = unw_backtrace (buf, 20)) < 3)
892 if ((n = unw_backtrace (buf, 20)) < 3)
902 if ((n = unw_backtrace (buf, 20)) < 3)
912 if ((n = unw_backtrace (buf, 20)) < 3)
922 if ((n = unw_backtrace (buf, 20)) < 3)
932 if ((n = unw_backtrace (buf, 20)) < 3)
942 if ((n = unw_backtrace (buf, 20)) < 3)
952 if ((n = unw_backtrace (buf, 20)) < 3)
962 if ((n = unw_backtrace (buf, 20)) < 3)
972 if ((n = unw_backtrace (buf, 20)) < 3)
982 if ((n = unw_backtrace (buf, 20)) < 3)
992 if ((n = unw_backtrace (buf, 20)) < 3)
1002 if ((n = unw_backtrace (buf, 20)) < 3)
1012 if ((n = unw_backtrace (buf, 20)) < 3)
1022 if ((n = unw_backtrace (buf, 20)) < 3)
1032 if ((n = unw_backtrace (buf, 20)) < 3)
1042 if ((n = unw_backtrace (buf, 20)) < 3)
1052 if ((n = unw_backtrace (buf, 20)) < 3)
1062 if ((n = unw_backtrace (buf, 20)) < 3)
1072 if ((n = unw_backtrace (buf, 20)) < 3)
1082 if ((n = unw_backtrace (buf, 20)) < 3)
1092 if ((n = unw_backtrace (buf, 20)) < 3)
1102 if ((n = unw_backtrace (buf, 20)) < 3)
1112 if ((n = unw_backtrace (buf, 20)) < 3)
1122 if ((n = unw_backtrace (buf, 20)) < 3)
1132 if ((n = unw_backtrace (buf, 20)) < 3)
1142 if ((n = unw_backtrace (buf, 20)) < 3)
1152 if ((n = unw_backtrace (buf, 20)) < 3)
1162 if ((n = unw_backtrace (buf, 20)) < 3)
1172 if ((n = unw_backtrace (buf, 20)) < 3)
1182 if ((n = unw_backtrace (buf, 20)) < 3)
1192 if ((n = unw_backtrace (buf, 20)) < 3)
1202 if ((n = unw_backtrace (buf, 20)) < 3)
1212 if ((n = unw_backtrace (buf, 20)) < 3)
1222 if ((n = unw_backtrace (buf, 20)) < 3)
1232 if ((n = unw_backtrace (buf, 20)) < 3)
1242 if ((n = unw_backtrace (buf, 20)) < 3)
1252 if ((n = unw_backtrace (buf, 20)) < 3)
1262 if ((n = unw_backtrace (buf, 20)) < 3)
1272 if ((n = unw_backtrace (buf, 20)) < 3)
1282 if ((n = unw_backtrace (buf, 20)) < 3)
1292 if ((n = unw_backtrace (buf, 20)) < 3)
1302 if ((n = unw_backtrace (buf, 20)) < 3)
1312 if ((n = unw_backtrace (buf, 20)) < 3)
1322 if ((n = unw_backtrace (buf, 20)) < 3)
1332 if ((n = unw_backtrace (buf, 20)) < 3)
1340 for (i = 0; i < ITERS; ++i) {
1476 pthread_t tid[NTHREAD];
1479 for (i = 0; i < NTHREAD; ++i)
1480 if (pthread_create (&tid[i], NULL, bar, NULL))
1483 for (i = 0; i < NTHREAD; ++i)
1484 if (pthread_join (tid[i], NULL))
1491 main (int argc, char **argv UNUSED)
1497 printf ("Caching: none\n");
1498 unw_set_caching_policy (unw_local_addr_space, UNW_CACHE_NONE);
1502 printf ("Caching: global\n");
1503 unw_set_caching_policy (unw_local_addr_space, UNW_CACHE_GLOBAL);
1507 printf ("Caching: per-thread\n");
1508 unw_set_caching_policy (unw_local_addr_space, UNW_CACHE_PER_THREAD);
1512 printf ("SUCCESS\n");