github.com/huandu/go@v0.0.0-20151114150818-04e615e41150/misc/cgo/testcshared/main0.c (about)

     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  
     5  #include <stdint.h>
     6  #include <stdio.h>
     7  
     8  #include "p.h"
     9  #include "libgo.h"
    10  
    11  // Tests libgo.so to export the following functions.
    12  //   int8_t DidInitRun();
    13  //   int8_t DidMainRun();
    14  //   int32_t FromPkg();
    15  int main(void) {
    16    int8_t ran_init = DidInitRun();
    17    if (!ran_init) {
    18      fprintf(stderr, "ERROR: DidInitRun returned unexpected results: %d\n",
    19              ran_init);
    20      return 1;
    21    }
    22    int8_t ran_main = DidMainRun();
    23    if (ran_main) {
    24      fprintf(stderr, "ERROR: DidMainRun returned unexpected results: %d\n",
    25              ran_main);
    26      return 1;
    27    }
    28    int32_t from_pkg = FromPkg();
    29    if (from_pkg != 1024) {
    30      fprintf(stderr, "ERROR: FromPkg=%d, want %d\n", from_pkg, 1024);
    31      return 1;
    32    }
    33    // test.bash looks for "PASS" to ensure this program has reached the end. 
    34    printf("PASS\n");
    35    return 0;
    36  }