-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverflush.go
More file actions
38 lines (33 loc) · 1.01 KB
/
Copy pathcoverflush.go
File metadata and controls
38 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: AGPL-3.0-or-later
//
//go:build coverflush
// coverflush adds a single //export, PilotCoverFlush, that the
// cintegration/ C harness calls just before exit. Without it, Go's
// coverage counters never make it to disk: when a c-shared library is
// loaded by a C program, the C `exit()` path skips Go's runtime
// at-exit handlers (which is what normally flushes covcounters.*).
//
// This file is build-tagged `coverflush` so the helper does NOT ship
// in production builds — it's purely a coverage-tooling escape hatch.
// The Makefile in cintegration/ adds `-tags coverflush` when building
// the instrumented dylib.
package main
/*
#include <stdlib.h>
*/
import "C"
import (
"os"
"runtime/coverage"
)
//export PilotCoverFlush
func PilotCoverFlush() *C.char {
dir := os.Getenv("GOCOVERDIR")
if dir == "" {
return C.CString(`{"error":"GOCOVERDIR not set"}`)
}
if err := coverage.WriteCountersDir(dir); err != nil {
return C.CString(`{"error":"` + err.Error() + `"}`)
}
return nil
}