2019-06-13 16:09:05 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
2019-06-21 15:04:34 +01:00
|
|
|
"time"
|
2019-06-13 16:09:05 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
2019-06-13 16:09:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestC(t *testing.T) {
|
2019-06-21 15:04:34 +01:00
|
|
|
ctx := testcontext.NewWithTimeout(t, 5*time.Minute)
|
2019-06-13 16:09:05 +01:00
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2019-10-17 08:42:22 +01:00
|
|
|
libuplinkInclude := ctx.CompileShared(t, "uplink", "storj.io/storj/lib/uplinkc")
|
2019-06-13 16:09:05 +01:00
|
|
|
|
|
|
|
currentdir, err := os.Getwd()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
definition := testcontext.Include{
|
|
|
|
Header: filepath.Join(currentdir, "uplink_definitions.h"),
|
|
|
|
}
|
|
|
|
|
|
|
|
ctests, err := filepath.Glob(filepath.Join("testdata", "*_test.c"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("ALL", func(t *testing.T) {
|
|
|
|
for _, ctest := range ctests {
|
|
|
|
ctest := ctest
|
2019-07-30 12:40:05 +01:00
|
|
|
testName := filepath.Base(ctest)
|
|
|
|
t.Run(testName, func(t *testing.T) {
|
2019-06-13 16:09:05 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2019-07-30 12:40:05 +01:00
|
|
|
testexe := ctx.CompileC(t, testcontext.CompileCOptions{
|
|
|
|
Dest: testName,
|
|
|
|
Sources: []string{ctest},
|
|
|
|
Includes: []testcontext.Include{
|
2019-10-17 08:42:22 +01:00
|
|
|
libuplinkInclude,
|
2019-07-30 12:40:05 +01:00
|
|
|
definition,
|
|
|
|
testcontext.CLibMath,
|
|
|
|
},
|
|
|
|
})
|
2019-06-13 16:09:05 +01:00
|
|
|
|
2019-12-06 18:03:22 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 5, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.DisablePeerCAWhitelist,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-06-13 16:09:05 +01:00
|
|
|
cmd := exec.Command(testexe)
|
|
|
|
cmd.Dir = filepath.Dir(testexe)
|
|
|
|
cmd.Env = append(os.Environ(),
|
|
|
|
"SATELLITE_0_ADDR="+planet.Satellites[0].Addr(),
|
2019-09-19 17:19:29 +01:00
|
|
|
"GATEWAY_0_API_KEY="+planet.Uplinks[0].APIKey[planet.Satellites[0].ID()].Serialize(),
|
2019-10-07 13:03:58 +01:00
|
|
|
"TMP_DIR"+ctx.Dir("c_temp"),
|
2019-06-13 16:09:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(string(out))
|
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
t.Log(string(out))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|