1// Copyright 2015 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package main
6
7import (
8	"fmt"
9	"os"
10	"syscall"
11	"time"
12
13	_ "testcarchive/p"
14)
15
16import "C"
17
18var initCh = make(chan int, 1)
19var ranMain bool
20
21func init() {
22	// emulate an exceedingly slow package initialization function
23	time.Sleep(100 * time.Millisecond)
24	initCh <- 42
25}
26
27func main() { ranMain = true }
28
29//export DidInitRun
30func DidInitRun() bool {
31	select {
32	case x := <-initCh:
33		if x != 42 {
34			// Just in case initCh was not correctly made.
35			println("want init value of 42, got: ", x)
36			syscall.Exit(2)
37		}
38		return true
39	default:
40		return false
41	}
42}
43
44//export DidMainRun
45func DidMainRun() bool { return ranMain }
46
47//export CheckArgs
48func CheckArgs() {
49	if len(os.Args) != 3 || os.Args[1] != "arg1" || os.Args[2] != "arg2" {
50		fmt.Printf("CheckArgs: want [_, arg1, arg2], got: %v\n", os.Args)
51		os.Exit(2)
52	}
53}
54