예제 #1
0
파일: aprof.cs 프로젝트: zjmit/go2cs
        public static void CgoCCodeSIGPROF()
        {
            var c = make_channel <bool>();

            go_(() => () =>
            {
                c.Receive();
                var start = time.Now();
                for (long i = 0L; i < 1e7F; i++)
                {
                    if (i % 1000L == 0L)
                    {
                        if (time.Since(start) > time.Second)
                        {
                            break;
                        }
                    }

                    C.GoNop();
                }

                c.Send(true);
            } ());

            ref bytes.Buffer buf = ref heap(out ptr <bytes.Buffer> _addr_buf);
예제 #2
0
        public static void CgoExternalThreadSignal()
        {
            if (len(os.Args) > 2L && os.Args[2L] == "crash")
            {
                var i = C.start_crashing_thread();
                if (i != 0L)
                {
                    fmt.Println("pthread_create failed:", i);
                    // Exit with 0 because parent expects us to crash.
                    return;
                }

                // We should crash immediately, but give it plenty of
                // time before failing (by exiting 0) in case we are
                // running on a slow system.
                time.Sleep(5L * time.Second);
                return;
            }

            var(out, err) = exec.Command(os.Args[0L], "CgoExternalThreadSignal", "crash").CombinedOutput();
            if (err == null)
            {
                fmt.Println("C signal did not crash as expected");
                fmt.Printf("\n%s\n", out);
                os.Exit(1L);
            }

            fmt.Println("OK");
        }
예제 #3
0
 public static void SigStack()
 {
     C.DoThread(0L);
     C.DoThread(1L);
     C.DoThread(0L);
     C.DoThread(1L);
     println("OK");
 }
예제 #4
0
파일: main.cs 프로젝트: zjmit/go2cs
 private static void cpuHogCFunction()
 {
     // Generates CPU profile samples including a Cgo call path.
     while (true)
     {
         C.CPUHogCFunction();
         runtime.Gosched();
     }
 }
예제 #5
0
파일: pprof.cs 프로젝트: zjmit/go2cs
        public static void CgoPprof()
        {
            runtime.SetCgoTraceback(0L, @unsafe.Pointer(C.pprofCgoTraceback), null, null);

            var(f, err) = ioutil.TempFile("", "prof");
            if (err != null)
            {
                fmt.Fprintln(os.Stderr, err);
                os.Exit(2L);
            }

            {
                var err__prev1 = err;

                var err = pprof.StartCPUProfile(f);

                if (err != null)
                {
                    fmt.Fprintln(os.Stderr, err);
                    os.Exit(2L);
                }

                err = err__prev1;
            }


            var t0 = time.Now();

            while (C.getCpuHogCount() < 2L && time.Since(t0) < time.Second)
            {
                C.cpuHog();
            }


            pprof.StopCPUProfile();

            var name = f.Name();

            {
                var err__prev1 = err;

                err = f.Close();

                if (err != null)
                {
                    fmt.Fprintln(os.Stderr, err);
                    os.Exit(2L);
                }

                err = err__prev1;
            }


            fmt.Println(name);
        }
예제 #6
0
        private static void pprofThread()
        {
            var(f, err) = ioutil.TempFile("", "prof");
            if (err != null)
            {
                fmt.Fprintln(os.Stderr, err);
                os.Exit(2L);
            }

            {
                var err__prev1 = err;

                var err = pprof.StartCPUProfile(f);

                if (err != null)
                {
                    fmt.Fprintln(os.Stderr, err);
                    os.Exit(2L);
                }

                err = err__prev1;
            }


            C.runCPUHogThread();

            var t0 = time.Now();

            while (C.getCPUHogThreadCount() < 2L && time.Since(t0) < time.Second)
            {
                time.Sleep(100L * time.Millisecond);
            }


            pprof.StopCPUProfile();

            var name = f.Name();

            {
                var err__prev1 = err;

                err = f.Close();

                if (err != null)
                {
                    fmt.Fprintln(os.Stderr, err);
                    os.Exit(2L);
                }

                err = err__prev1;
            }


            fmt.Println(name);
        }
예제 #7
0
        private static void Main()
        {
            long data = 0L;

            go_(() => () =>
            {
                data = 1L;
                C.Notify();
            } ());
            C.Wait();
            _ = data;
        }
예제 #8
0
파일: catchpanic.cs 프로젝트: zjmit/go2cs
        // Test that the SIGABRT raised by panic can be caught by an early signal handler.
        public static void CgoCatchPanic() => func((_, panic, __) =>
        {
            {
                var(_, ok) = os.LookupEnv("CGOCATCHPANIC_EARLY_HANDLER");

                if (!ok)
                {
                    C.registerAbortHandler();
                }
            }

            panic("catch me");
        });
예제 #9
0
        public static void CgoRaceSignal()
        {
            // The failure symptom is that the program hangs because of a
            // deadlock in malloc, so set an alarm.
            go_(() => () =>
            {
                time.Sleep(5L * time.Second);
                fmt.Println("Hung for 5 seconds");
                os.Exit(1L);
            } ());

            C.runRaceSignalThread();
            fmt.Println("OK");
        }
예제 #10
0
파일: lockosthread.cs 프로젝트: zjmit/go2cs
        private static void init()
        {
            registerInit("LockOSThreadMain", () =>
            {
                // init is guaranteed to run on the main thread.
                mainThread = C.pthread_self();
            });
            register("LockOSThreadMain", LockOSThreadMain);

            registerInit("LockOSThreadAlt", () =>
            {
                // Lock the OS thread now so main runs on the main thread.
                runtime.LockOSThread();
            });
            register("LockOSThreadAlt", LockOSThreadAlt);
        }
예제 #11
0
파일: eintr.cs 프로젝트: zjmit/go2cs
        // Test various operations when a signal handler is installed without
        // the SA_RESTART flag. This tests that the os and net APIs handle EINTR.
        public static void EINTR()
        {
            {
                var errno__prev1 = errno;

                var errno = C.clearRestart(C.@int(syscall.SIGURG));

                if (errno != 0L)
                {
                    log.Fatal(syscall.Errno(errno));
                }

                errno = errno__prev1;
            }

            {
                var errno__prev1 = errno;

                errno = C.clearRestart(C.@int(syscall.SIGWINCH));

                if (errno != 0L)
                {
                    log.Fatal(syscall.Errno(errno));
                }

                errno = errno__prev1;
            }

            {
                var errno__prev1 = errno;

                errno = C.clearRestart(C.@int(syscall.SIGCHLD));

                if (errno != 0L)
                {
                    log.Fatal(syscall.Errno(errno));
                }

                errno = errno__prev1;
            }


            ref sync.WaitGroup wg = ref heap(out ptr <sync.WaitGroup> _addr_wg);
예제 #12
0
        public static void TracebackContext()
        {
            runtime.SetCgoTraceback(0L, @unsafe.Pointer(C.tcTraceback), @unsafe.Pointer(C.tcContext), @unsafe.Pointer(C.tcSymbolizer));
            C.C1();
            {
                var got = C.getContextCount();

                if (got != 0L)
                {
                    fmt.Printf("at end contextCount == %d, expected 0\n", got);
                    tracebackOK = false;
                }
            }

            if (tracebackOK)
            {
                fmt.Println("OK");
            }
        }
예제 #13
0
파일: segv.cs 프로젝트: zjmit/go2cs
        public static void SegvInCgo()
        {
            var c = make_channel <bool>();

            go_(() => () =>
            {
                close(c);
                while (true)
                {
                    C.nop();
                }
            } ());

            c.Receive();

            syscall.Kill(syscall.Getpid(), syscall.SIGSEGV);

            // Give the OS time to deliver the signal.
            time.Sleep(time.Second);
        }
예제 #14
0
파일: lockosthread.cs 프로젝트: zjmit/go2cs
        public static void LockOSThreadAlt()
        {
            // This is running locked to the main OS thread.

            C.pthread_t subThread = default;
            var         ready     = make_channel <bool>(1L);

            C.threadExited = 0L;
            go_(() => () =>
            {
                // This goroutine must be running on a new thread.
                runtime.LockOSThread();
                subThread = C.pthread_self();
                // Register a pthread destructor so we can tell this
                // thread has exited.
                ref C.pthread_key_t key = ref heap(out ptr <C.pthread_key_t> _addr_key);
                C.pthread_key_create(_addr_key, new ptr <ptr <array <byte> > >(@unsafe.Pointer(C.setExited)));
                C.pthread_setspecific(key, @unsafe.Pointer(@new <int>()));
                ready.Send(true);
                // Exit with the thread locked.
            } ());
예제 #15
0
파일: lockosthread.cs 프로젝트: zjmit/go2cs
        public static void LockOSThreadMain()
        {
            // This requires GOMAXPROCS=1 from the beginning to reliably
            // start a goroutine on the main thread.
            if (runtime.GOMAXPROCS(-1L) != 1L)
            {
                println("requires GOMAXPROCS=1");
                os.Exit(1L);
            }

            var ready = make_channel <bool>(1L);

            go_(() => () =>
            {
                // Because GOMAXPROCS=1, this *should* be on the main
                // thread. Stay there.
                runtime.LockOSThread();
                var self = C.pthread_self();
                if (C.pthread_equal(mainThread, self) == 0L)
                {
                    println("failed to start goroutine on main thread");
                    os.Exit(1L);
                }
                // Exit with the thread locked, which should exit the
                // main thread.
                ready.Send(true);
            } ());
            ready.Receive();
            time.Sleep(1L * time.Millisecond);
            // Check that this goroutine is still running on a different
            // thread.
            self = C.pthread_self();
            if (C.pthread_equal(mainThread, self) != 0L)
            {
                println("goroutine migrated to locked thread");
                os.Exit(1L);
            }

            println("OK");
        }
예제 #16
0
파일: numgoroutine.cs 프로젝트: zjmit/go2cs
        public static void NumGoroutine()
        {
            // Test that there are just the expected number of goroutines
            // running. Specifically, test that the spare M's goroutine
            // doesn't show up.
            {
                var(_, ok) = checkNumGoroutine("first", 1L + baseGoroutines);

                if (!ok)
                {
                    return;
                }

                // Test that the goroutine for a callback from C appears.
            }

            // Test that the goroutine for a callback from C appears.
            C.CheckNumGoroutine();

            if (!callbackok)
            {
                return;
            }

            // Make sure we're back to the initial goroutines.
            {
                (_, ok) = checkNumGoroutine("third", 1L + baseGoroutines);

                if (!ok)
                {
                    return;
                }
            }


            fmt.Println("OK");
        }
예제 #17
0
 public static void CrashTraceback()
 {
     runtime.SetCgoTraceback(0L, @unsafe.Pointer(C.cgoTraceback), null, @unsafe.Pointer(C.cgoSymbolizer));
     C.f1();
 }
예제 #18
0
 public static uint GetThread()
 {
     return(uint32(C.agetthread()));
 }
예제 #19
0
 public static void CgoExternalThreadPanic()
 {
     C.start();
 }
예제 #20
0
파일: util_gccgo.cs 프로젝트: zjmit/go2cs
 private static bool cansse2()
 {
     return(C.supports_sse2() != 0L);
 }
예제 #21
0
파일: sigpanic.cs 프로젝트: zjmit/go2cs
 public static void TracebackSigpanic()
 {
     C.f1();
 }
예제 #22
0
 public static void BigStack()
 {
     // Create a large thread stack and call back into Go to test
     // if Go correctly determines the stack bounds.
     C.bigStack((C.callback.val)(C.goBigStack1));
 }
예제 #23
0
 private static @string Error(this cgoError _p0)
 {
     fmt.Print(""); // necessary to trigger the deadlock
     return(C.GoString(C.geterror()));
 }
예제 #24
0
파일: main.cs 프로젝트: zjmit/go2cs
 // CallMeBack call backs C code.
 //export CallMeBack
 public static void CallMeBack(C.callmeBackFunc callback)
 {
     C.bridgeCallback(callback);
 }
예제 #25
0
 public static void CgoDLLImportsMain()
 {
     C.getthread();
     windows.GetThread();
     println("OK");
 }
예제 #26
0
 public static void EnsureDropM()
 {
     C.CheckM();
     fmt.Println("OK");
 }
예제 #27
0
파일: cgo_unix.cs 프로젝트: zjmit/go2cs
 private static @string Error(this addrinfoErrno eai)
 {
     return(C.GoString(C.gai_strerror(C.@int(eai))));
 }
예제 #28
0
 //export G1
 public static void G1()
 {
     C.C2();
 }
예제 #29
0
파일: lib.cs 프로젝트: zjmit/go2cs
 public static void DoC()
 {
     C.function();
     fmt.Println("called c function");
 }