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);
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"); }
public static void SigStack() { C.DoThread(0L); C.DoThread(1L); C.DoThread(0L); C.DoThread(1L); println("OK"); }
private static void cpuHogCFunction() { // Generates CPU profile samples including a Cgo call path. while (true) { C.CPUHogCFunction(); runtime.Gosched(); } }
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); }
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); }
private static void Main() { long data = 0L; go_(() => () => { data = 1L; C.Notify(); } ()); C.Wait(); _ = data; }
// 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"); });
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"); }
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); }
// 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);
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"); } }
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); }
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. } ());
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"); }
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"); }
public static void CrashTraceback() { runtime.SetCgoTraceback(0L, @unsafe.Pointer(C.cgoTraceback), null, @unsafe.Pointer(C.cgoSymbolizer)); C.f1(); }
public static uint GetThread() { return(uint32(C.agetthread())); }
public static void CgoExternalThreadPanic() { C.start(); }
private static bool cansse2() { return(C.supports_sse2() != 0L); }
public static void TracebackSigpanic() { C.f1(); }
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)); }
private static @string Error(this cgoError _p0) { fmt.Print(""); // necessary to trigger the deadlock return(C.GoString(C.geterror())); }
// CallMeBack call backs C code. //export CallMeBack public static void CallMeBack(C.callmeBackFunc callback) { C.bridgeCallback(callback); }
public static void CgoDLLImportsMain() { C.getthread(); windows.GetThread(); println("OK"); }
public static void EnsureDropM() { C.CheckM(); fmt.Println("OK"); }
private static @string Error(this addrinfoErrno eai) { return(C.GoString(C.gai_strerror(C.@int(eai)))); }
//export G1 public static void G1() { C.C2(); }
public static void DoC() { C.function(); fmt.Println("called c function"); }