...

Text file src/cmd/cgo/internal/testcshared/testdata/main0.c

Documentation: cmd/cgo/internal/testcshared/testdata

     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//   uint32_t Divu(uint32_t, uint32_t);
    16int main(void) {
    17  int8_t ran_init = DidInitRun();
    18  if (!ran_init) {
    19    fprintf(stderr, "ERROR: DidInitRun returned unexpected results: %d\n",
    20            ran_init);
    21    return 1;
    22  }
    23  int8_t ran_main = DidMainRun();
    24  if (ran_main) {
    25    fprintf(stderr, "ERROR: DidMainRun returned unexpected results: %d\n",
    26            ran_main);
    27    return 1;
    28  }
    29  int32_t from_pkg = FromPkg();
    30  if (from_pkg != 1024) {
    31    fprintf(stderr, "ERROR: FromPkg=%d, want %d\n", from_pkg, 1024);
    32    return 1;
    33  }
    34  uint32_t divu = Divu(2264, 31);
    35  if (divu != 73) {
    36    fprintf(stderr, "ERROR: Divu(2264, 31)=%d, want %d\n", divu, 73);
    37    return 1;
    38  }
    39  // test.bash looks for "PASS" to ensure this program has reached the end. 
    40  printf("PASS\n");
    41  return 0;
    42}

View as plain text