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.
9 int check_int8(void* handle
, const char* fname
, int8_t want
) {
11 fn
= (int8_t (*)())dlsym(handle
, fname
);
13 fprintf(stderr
, "ERROR: missing %s: %s\n", fname
, dlerror());
16 signed char ret
= fn();
18 fprintf(stderr
, "ERROR: %s=%d, want %d\n", fname
, ret
, want
);
24 int check_int32(void* handle
, const char* fname
, int32_t want
) {
26 fn
= (int32_t (*)())dlsym(handle
, fname
);
28 fprintf(stderr
, "ERROR: missing %s: %s\n", fname
, dlerror());
33 fprintf(stderr
, "ERROR: %s=%d, want %d\n", fname
, ret
, want
);
39 // Tests libgo.so to export the following functions.
40 // int8_t DidInitRun() // returns true
41 // int8_t DidMainRun() // returns true
42 // int32_t FromPkg() // returns 1024
43 int main(int argc
, char** argv
) {
44 void* handle
= dlopen(argv
[1], RTLD_LAZY
| RTLD_GLOBAL
);
46 fprintf(stderr
, "ERROR: failed to open the shared library: %s\n",
52 ret
= check_int8(handle
, "DidInitRun", 1);
57 ret
= check_int8(handle
, "DidMainRun", 0);
62 ret
= check_int32(handle
, "FromPkg", 1024);
66 // test.bash looks for "PASS" to ensure this program has reached the end.