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-06-15 12:23:12 +01:00
|
|
|
"go.uber.org/zap/zapcore"
|
|
|
|
"go.uber.org/zap/zaptest"
|
2019-06-13 16:09:05 +01:00
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2019-06-15 12:23:12 +01:00
|
|
|
func RunPlanet(t *testing.T, run func(ctx *testcontext.Context, planet *testplanet.Planet)) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
|
|
|
planet, err := testplanet.NewCustom(
|
|
|
|
zaptest.NewLogger(t, zaptest.Level(zapcore.WarnLevel)),
|
|
|
|
testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
2019-08-26 19:40:44 +01:00
|
|
|
StorageNodeCount: 5,
|
2019-06-15 12:23:12 +01:00
|
|
|
UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.DisablePeerCAWhitelist,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(planet.Shutdown)
|
|
|
|
planet.Start(ctx)
|
|
|
|
|
|
|
|
run(ctx, planet)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
RunPlanet(t, func(ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|