~ubuntu-branches/ubuntu/hardy/libgc/hardy-updates

« back to all changes in this revision

Viewing changes to tests/test.c

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Murray
  • Date: 2005-02-03 00:50:53 UTC
  • mto: (3.1.1 etch) (1.2.4 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050203005053-9c0v9r2qcm2g1cfp
Tags: upstream-6.4
ImportĀ upstreamĀ versionĀ 6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
#   include <pthread.h>
69
69
# endif
70
70
 
71
 
# ifdef GC_WIN32_THREADS
72
 
#   ifndef MSWINCE
73
 
#     include <process.h>
74
 
#     define GC_CreateThread(a,b,c,d,e,f) ((HANDLE) _beginthreadex(a,b,c,d,e,f))
75
 
#   endif
 
71
# if defined(GC_WIN32_THREADS) && !defined(GC_PTHREADS)
76
72
    static CRITICAL_SECTION incr_cs;
77
73
# endif
78
74
 
 
75
#ifdef __STDC__
 
76
# include <stdarg.h>
 
77
#endif
 
78
 
79
79
 
80
80
/* Allocation Statistics */
81
81
int stubborn_count = 0;
208
208
#ifdef GC_GCJ_SUPPORT
209
209
 
210
210
#include "gc_mark.h"
211
 
#include "private/dbg_mlc.h"  /* For USR_PTR_FROM_BASE */
212
211
#include "gc_gcj.h"
213
212
 
214
213
/* The following struct emulates the vtable in gcj.     */
233
232
    sexpr x;
234
233
    if (1 == env) {
235
234
        /* Object allocated with debug allocator.       */
236
 
        addr = (word *)USR_PTR_FROM_BASE(addr);
 
235
        addr = (word *)GC_USR_PTR_FROM_BASE(addr);
237
236
    }
238
237
    x = (sexpr)(addr + 1); /* Skip the vtable pointer. */
239
238
    mark_stack_ptr = GC_MARK_AND_PUSH(
376
375
sexpr reverse(x)
377
376
sexpr x;
378
377
{
 
378
#   ifdef TEST_WITH_SYSTEM_MALLOC
 
379
      malloc(100000);
 
380
#   endif
379
381
    return( reverse1(x, nil) );
380
382
}
381
383
 
517
519
    }
518
520
}
519
521
 
520
 
/* Try to force a to be strangely aligned */
521
 
struct {
522
 
  char dummy;
523
 
  sexpr aa;
524
 
} A;
525
 
#define a A.aa
526
 
 
527
522
/*
528
523
 * A tiny list reversal test to check thread creation.
529
524
 */
530
525
#ifdef THREADS
531
526
 
532
 
# ifdef GC_WIN32_THREADS
533
 
    unsigned __stdcall tiny_reverse_test(void * arg)
 
527
# if defined(GC_WIN32_THREADS) && !defined(CYGWIN32)
 
528
    DWORD  __stdcall tiny_reverse_test(void * arg)
534
529
# else
535
530
    void * tiny_reverse_test(void * arg)
536
531
# endif
565
560
# elif defined(GC_WIN32_THREADS)
566
561
    void fork_a_thread()
567
562
    {
568
 
        unsigned thread_id;
 
563
        DWORD thread_id;
569
564
        HANDLE h;
570
565
        h = GC_CreateThread(NULL, 0, tiny_reverse_test, 0, 0, &thread_id);
571
566
        if (h == (HANDLE)NULL) {
594
589
 
595
590
#endif 
596
591
 
 
592
/* Try to force a to be strangely aligned */
 
593
struct {
 
594
  char dummy;
 
595
  sexpr aa;
 
596
} A;
 
597
#define a A.aa
 
598
 
597
599
/*
598
600
 * Repeatedly reverse lists built out of very different sized cons cells.
599
601
 * Check that we didn't lose anything.
714
716
    b = c = 0;
715
717
}
716
718
 
 
719
#undef a
 
720
 
717
721
/*
718
722
 * The rest of this builds balanced binary trees, checks that they don't
719
723
 * disappear, and tests finalization.
748
752
# if  defined(GC_PTHREADS)
749
753
    static pthread_mutex_t incr_lock = PTHREAD_MUTEX_INITIALIZER;
750
754
    pthread_mutex_lock(&incr_lock);
751
 
# endif
752
 
# ifdef GC_WIN32_THREADS
753
 
    EnterCriticalSection(&incr_cs);
 
755
# else
 
756
#   ifdef GC_WIN32_THREADS
 
757
      EnterCriticalSection(&incr_cs);
 
758
#   endif
754
759
# endif
755
760
  if ((int)(GC_word)client_data != t -> level) {
756
761
     (void)GC_printf0("Wrong finalization data - collector is broken\n");
757
762
     FAIL;
758
763
  }
759
764
  finalized_count++;
 
765
  t -> level = -1;      /* detect duplicate finalization immediately */
760
766
# ifdef PCR
761
767
    PCR_ThCrSec_ExitSys();
762
768
# endif
765
771
# endif
766
772
# if defined(GC_PTHREADS)
767
773
    pthread_mutex_unlock(&incr_lock);
768
 
# endif
769
 
# ifdef GC_WIN32_THREADS
770
 
    LeaveCriticalSection(&incr_cs);
 
774
# else
 
775
#   ifdef GC_WIN32_THREADS
 
776
      LeaveCriticalSection(&incr_cs);
 
777
#   endif
771
778
# endif
772
779
}
773
780
 
839
846
#         if defined(GC_PTHREADS)
840
847
            static pthread_mutex_t incr_lock = PTHREAD_MUTEX_INITIALIZER;
841
848
            pthread_mutex_lock(&incr_lock);
842
 
#         endif
843
 
#         ifdef GC_WIN32_THREADS
844
 
            EnterCriticalSection(&incr_cs);
 
849
#         else
 
850
#           ifdef GC_WIN32_THREADS
 
851
              EnterCriticalSection(&incr_cs);
 
852
#           endif
845
853
#         endif
846
854
                /* Losing a count here causes erroneous report of failure. */
847
855
          finalizable_count++;
854
862
#         endif
855
863
#         if defined(GC_PTHREADS)
856
864
            pthread_mutex_unlock(&incr_lock);
857
 
#         endif
858
 
#         ifdef GC_WIN32_THREADS
859
 
            LeaveCriticalSection(&incr_cs);
 
865
#         else
 
866
#           ifdef GC_WIN32_THREADS
 
867
              LeaveCriticalSection(&incr_cs);
 
868
#           endif
860
869
#         endif
861
870
        }
862
871
 
1161
1170
    fail_count++;
1162
1171
}   
1163
1172
 
 
1173
static void uniq(void *p, ...) {
 
1174
  va_list a;
 
1175
  void *q[100];
 
1176
  int n = 0, i, j;
 
1177
  q[n++] = p;
 
1178
  va_start(a,p);
 
1179
  for (;(q[n] = va_arg(a,void *));n++) ;
 
1180
  va_end(a);
 
1181
  for (i=0; i<n; i++)
 
1182
    for (j=0; j<i; j++)
 
1183
      if (q[i] == q[j]) {
 
1184
        GC_printf0(
 
1185
              "Apparently failed to mark form some function arguments.\n"
 
1186
              "Perhaps GC_push_regs was configured incorrectly?\n"
 
1187
        );
 
1188
        FAIL;
 
1189
      }
 
1190
}
 
1191
 
1164
1192
#endif /* __STDC__ */
1165
1193
 
1166
1194
#ifdef THREADS
1227
1255
        FAIL;
1228
1256
      }
1229
1257
      if (!TEST_FAIL_COUNT(1)) {
1230
 
#       if!(defined(RS6000) || defined(POWERPC) || defined(IA64))
 
1258
#       if!(defined(RS6000) || defined(POWERPC) || defined(IA64)) || defined(M68K)
1231
1259
          /* ON RS6000s function pointers point to a descriptor in the  */
1232
1260
          /* data segment, so there should have been no failures.       */
 
1261
          /* The same applies to IA64.  Something similar seems to      */
 
1262
          /* be going on with NetBSD/M68K.                              */
1233
1263
          (void)GC_printf0("GC_is_visible produced wrong failure indication\n");
1234
1264
          FAIL;
1235
1265
#       endif
1241
1271
                "GC_is_valid_displacement produced incorrect result\n");
1242
1272
        FAIL;
1243
1273
      }
 
1274
#     if defined(__STDC__) && !defined(MSWIN32) && !defined(MSWINCE)
 
1275
        /* Harder to test under Windows without a gc.h declaration.  */
 
1276
        {
 
1277
          size_t i;
 
1278
          extern void *GC_memalign();
 
1279
 
 
1280
          GC_malloc(17);
 
1281
          for (i = sizeof(GC_word); i < 512; i *= 2) {
 
1282
            GC_word result = (GC_word) GC_memalign(i, 17);
 
1283
            if (result % i != 0 || result == 0 || *(int *)result != 0) FAIL;
 
1284
          } 
 
1285
        }
 
1286
#     endif
1244
1287
#     ifndef ALL_INTERIOR_POINTERS
1245
1288
#      if defined(RS6000) || defined(POWERPC)
1246
1289
        if (!TEST_FAIL_COUNT(1)) {
1261
1304
      GC_REGISTER_DISPLACEMENT(sizeof(struct fake_vtable *));
1262
1305
      GC_init_gcj_malloc(0, (void *)fake_gcj_mark_proc);
1263
1306
#   endif
 
1307
    /* Make sure that fn arguments are visible to the collector.        */
 
1308
#   ifdef __STDC__
 
1309
      uniq(
 
1310
        GC_malloc(12), GC_malloc(12), GC_malloc(12),
 
1311
        (GC_gcollect(),GC_malloc(12)),
 
1312
        GC_malloc(12), GC_malloc(12), GC_malloc(12),
 
1313
        (GC_gcollect(),GC_malloc(12)),
 
1314
        GC_malloc(12), GC_malloc(12), GC_malloc(12),
 
1315
        (GC_gcollect(),GC_malloc(12)),
 
1316
        GC_malloc(12), GC_malloc(12), GC_malloc(12),
 
1317
        (GC_gcollect(),GC_malloc(12)),
 
1318
        GC_malloc(12), GC_malloc(12), GC_malloc(12),
 
1319
        (GC_gcollect(),GC_malloc(12)),
 
1320
        (void *)0);
 
1321
#   endif
1264
1322
    /* Repeated list reversal test. */
1265
1323
        reverse_test();
1266
1324
#   ifdef PRINTSTATS
1440
1498
        /* Cheat and let stdio initialize toolbox for us.       */
1441
1499
        printf("Testing GC Macintosh port.\n");
1442
1500
#   endif
1443
 
    GC_INIT();  /* Only needed if gc is dynamic library.        */
 
1501
    GC_INIT();  /* Only needed on a few platforms.      */
1444
1502
    (void) GC_set_warn_proc(warn_proc);
1445
 
#   if (defined(MPROTECT_VDB) || defined(PROC_VDB)) && !defined(MAKE_BACK_GRAPH)
 
1503
#   if (defined(MPROTECT_VDB) || defined(PROC_VDB)) \
 
1504
          && !defined(MAKE_BACK_GRAPH)
1446
1505
      GC_enable_incremental();
1447
1506
      (void) GC_printf0("Switched to incremental mode\n");
1448
1507
#     if defined(MPROTECT_VDB)
1449
1508
        (void)GC_printf0("Emulating dirty bits with mprotect/signals\n");
1450
1509
#     else
 
1510
#       ifdef PROC_VDB
1451
1511
        (void)GC_printf0("Reading dirty bits from /proc\n");
 
1512
#       else
 
1513
    (void)GC_printf0("Using DEFAULT_VDB dirty bit implementation\n");
 
1514
#       endif
1452
1515
#      endif
1453
1516
#   endif
1454
1517
    run_one_test();
1480
1543
}
1481
1544
# endif
1482
1545
 
1483
 
#ifdef GC_WIN32_THREADS
 
1546
#if defined(GC_WIN32_THREADS) && !defined(CYGWIN32)
1484
1547
 
1485
 
unsigned __stdcall thr_run_one_test(void *arg)
 
1548
DWORD __stdcall thr_run_one_test(void *arg)
1486
1549
{
1487
1550
  run_one_test();
1488
1551
  return 0;
1514
1577
  return ret;
1515
1578
}
1516
1579
 
1517
 
unsigned __stdcall thr_window(void *arg)
 
1580
DWORD __stdcall thr_window(void *arg)
1518
1581
{
1519
1582
  WNDCLASS win_class = {
1520
1583
    CS_NOCLOSE,
1576
1639
# ifdef MSWINCE
1577
1640
    HANDLE win_thr_h;
1578
1641
# endif
1579
 
  unsigned thread_id;
 
1642
  DWORD thread_id;
1580
1643
# if 0
1581
1644
    GC_enable_incremental();
1582
1645
# endif
 
1646
  GC_init();
1583
1647
  InitializeCriticalSection(&incr_cs);
1584
1648
  (void) GC_set_warn_proc(warn_proc);
1585
1649
# ifdef MSWINCE
1727
1791
          (void)GC_printf0("pthread_default_stacksize_np failed.\n");
1728
1792
        }
1729
1793
#   endif       /* GC_HPUX_THREADS */
 
1794
    GC_INIT();
 
1795
 
1730
1796
    pthread_attr_init(&attr);
1731
 
#   if defined(GC_IRIX_THREADS) || defined(GC_FREEBSD_THREADS)
 
1797
#   if defined(GC_IRIX_THREADS) || defined(GC_FREEBSD_THREADS) \
 
1798
        || defined(GC_DARWIN_THREADS) || defined(GC_AIX_THREADS)
1732
1799
        pthread_attr_setstacksize(&attr, 1000000);
1733
1800
#   endif
1734
1801
    n_tests = 0;
1735
 
#   if  defined(MPROTECT_VDB) && !defined(PARALLEL_MARK) &&!defined(REDIRECT_MALLOC) && !defined(MAKE_BACK_GRAPH)
 
1802
#   if (defined(MPROTECT_VDB)) \
 
1803
            && !defined(PARALLEL_MARK) &&!defined(REDIRECT_MALLOC) \
 
1804
            && !defined(MAKE_BACK_GRAPH)
1736
1805
        GC_enable_incremental();
1737
1806
        (void) GC_printf0("Switched to incremental mode\n");
1738
 
        (void) GC_printf0("Emulating dirty bits with mprotect/signals\n");
 
1807
#     if defined(MPROTECT_VDB)
 
1808
        (void)GC_printf0("Emulating dirty bits with mprotect/signals\n");
 
1809
#     else
 
1810
#       ifdef PROC_VDB
 
1811
            (void)GC_printf0("Reading dirty bits from /proc\n");
 
1812
#       else
 
1813
            (void)GC_printf0("Using DEFAULT_VDB dirty bit implementation\n");
 
1814
#       endif
 
1815
#     endif
1739
1816
#   endif
1740
1817
    (void) GC_set_warn_proc(warn_proc);
1741
1818
    if ((code = pthread_key_create(&fl_key, 0)) != 0) {