@@ -25,15 +25,17 @@ package main
2525import (
2626 "context"
2727 "flag"
28+ "fmt"
2829 "os"
30+ "os/exec"
2931 "strconv"
3032 "sync"
3133 "testing"
3234
3335 ctrdlog "github.com/containerd/containerd/log"
3436 log "github.com/sirupsen/logrus"
3537 "github.com/stretchr/testify/require"
36- ctriface "github.com/vhive-serverless/vhive/ctriface"
38+ "github.com/vhive-serverless/vhive/ctriface"
3739)
3840
3941const (
@@ -77,29 +79,16 @@ func TestMain(m *testing.M) {
7779 log .Infof ("Drop cache: %t" , ! * isWithCache )
7880 log .Infof ("Bench dir: %s" , * benchDir )
7981
80- orch = ctriface .NewOrchestrator (
81- "devmapper" ,
82- "" ,
83- ctriface .WithTestModeOn (true ),
84- ctriface .WithSnapshots (* isSnapshotsEnabledTest ),
85- ctriface .WithUPF (* isUPFEnabledTest ),
86- ctriface .WithMetricsMode (* isMetricsModeTest ),
87- ctriface .WithLazyMode (* isLazyModeTest ),
88- )
89-
9082 ret := m .Run ()
91-
92- err := orch .StopActiveVMs ()
93- if err != nil {
94- log .Printf ("Failed to stop VMs, err: %v\n " , err )
95- }
96-
97- orch .Cleanup ()
98-
9983 os .Exit (ret )
10084}
10185
10286func TestSendToFunctionSerial (t * testing.T ) {
87+ if err := initFirecrackerContainerd (); err != nil {
88+ t .Fatalf ("Failed to initialize firecracker containerd: %v" , err )
89+ }
90+ defer cleanup ()
91+
10392 fID := "1"
10493 var (
10594 servedTh uint64
@@ -122,6 +111,11 @@ func TestSendToFunctionSerial(t *testing.T) {
122111}
123112
124113func TestSendToFunctionParallel (t * testing.T ) {
114+ if err := initFirecrackerContainerd (); err != nil {
115+ t .Fatalf ("Failed to initialize firecracker containerd: %v" , err )
116+ }
117+ defer cleanup ()
118+
125119 fID := "2"
126120 var (
127121 servedTh uint64
@@ -148,6 +142,11 @@ func TestSendToFunctionParallel(t *testing.T) {
148142}
149143
150144func TestStartSendStopTwice (t * testing.T ) {
145+ if err := initFirecrackerContainerd (); err != nil {
146+ t .Fatalf ("Failed to initialize firecracker containerd: %v" , err )
147+ }
148+ defer cleanup ()
149+
151150 fID := "3"
152151 var (
153152 servedTh uint64 = 1
@@ -173,6 +172,11 @@ func TestStartSendStopTwice(t *testing.T) {
173172}
174173
175174func TestStatsNotNumericFunction (t * testing.T ) {
175+ if err := initFirecrackerContainerd (); err != nil {
176+ t .Fatalf ("Failed to initialize firecracker containerd: %v" , err )
177+ }
178+ defer cleanup ()
179+
176180 fID := "not-cld"
177181 var (
178182 servedTh uint64 = 1
@@ -194,6 +198,11 @@ func TestStatsNotNumericFunction(t *testing.T) {
194198}
195199
196200func TestStatsNotColdFunction (t * testing.T ) {
201+ if err := initFirecrackerContainerd (); err != nil {
202+ t .Fatalf ("Failed to initialize firecracker containerd: %v" , err )
203+ }
204+ defer cleanup ()
205+
197206 fID := "4"
198207 var (
199208 servedTh uint64 = 1
@@ -215,6 +224,11 @@ func TestStatsNotColdFunction(t *testing.T) {
215224}
216225
217226func TestSaveMemorySerial (t * testing.T ) {
227+ if err := initFirecrackerContainerd (); err != nil {
228+ t .Fatalf ("Failed to initialize firecracker containerd: %v" , err )
229+ }
230+ defer cleanup ()
231+
218232 fID := "5"
219233 var (
220234 servedTh uint64 = 40
@@ -236,6 +250,11 @@ func TestSaveMemorySerial(t *testing.T) {
236250}
237251
238252func TestSaveMemoryParallel (t * testing.T ) {
253+ if err := initFirecrackerContainerd (); err != nil {
254+ t .Fatalf ("Failed to initialize firecracker containerd: %v" , err )
255+ }
256+ defer cleanup ()
257+
239258 fID := "6"
240259 var (
241260 servedTh uint64 = 40
@@ -266,6 +285,11 @@ func TestSaveMemoryParallel(t *testing.T) {
266285}
267286
268287func TestDirectStartStopVM (t * testing.T ) {
288+ if err := initFirecrackerContainerd (); err != nil {
289+ t .Fatalf ("Failed to initialize firecracker containerd: %v" , err )
290+ }
291+ defer cleanup ()
292+
269293 fID := "7"
270294 var (
271295 servedTh uint64
@@ -285,6 +309,10 @@ func TestDirectStartStopVM(t *testing.T) {
285309}
286310
287311func TestAllFunctions (t * testing.T ) {
312+ if err := initFirecrackerContainerd (); err != nil {
313+ t .Fatalf ("Failed to initialize firecracker containerd: %v" , err )
314+ }
315+ defer cleanup ()
288316
289317 if testing .Short () {
290318 t .Skip ("skipping TestAllFunctions in non-nightly runs." )
@@ -340,3 +368,52 @@ func TestAllFunctions(t *testing.T) {
340368 }
341369 vmGroup .Wait ()
342370}
371+
372+ func initFirecrackerContainerd () error {
373+ firecrackerBin := os .Getenv ("FIRECRACKER_BIN" )
374+ firecrackerConfigPath := os .Getenv ("FIRECRACKER_CONFIG_PATH" )
375+ logOut := os .Getenv ("LOG_OUT" )
376+ logErr := os .Getenv ("LOG_ERR" )
377+
378+ logOutFile , err := os .OpenFile (logOut , os .O_WRONLY | os .O_CREATE | os .O_APPEND , 0644 )
379+ if err != nil {
380+ return fmt .Errorf ("failed to open log file %s: %w" , logOut , err )
381+ }
382+ defer logOutFile .Close ()
383+
384+ logErrFile , err := os .OpenFile (logErr , os .O_WRONLY | os .O_CREATE | os .O_APPEND , 0644 )
385+ if err != nil {
386+ return fmt .Errorf ("failed to open error log file %s: %w" , logErr , err )
387+ }
388+ defer logErrFile .Close ()
389+
390+ cmd := exec .Command (firecrackerBin , "--config" , firecrackerConfigPath )
391+ cmd .Stdout = logOutFile
392+ cmd .Stderr = logErrFile
393+
394+ if err := cmd .Start (); err != nil {
395+ return fmt .Errorf ("failed to start firecracker containerd: %w" , err )
396+ }
397+
398+ orch = ctriface .NewOrchestrator (
399+ "devmapper" ,
400+ "" ,
401+ ctriface .WithTestModeOn (true ),
402+ ctriface .WithSnapshots (* isSnapshotsEnabledTest ),
403+ ctriface .WithUPF (* isUPFEnabledTest ),
404+ ctriface .WithMetricsMode (* isMetricsModeTest ),
405+ ctriface .WithLazyMode (* isLazyModeTest ),
406+ )
407+
408+ return nil
409+ }
410+
411+ func cleanup () {
412+ if orch != nil {
413+ if err := orch .StopActiveVMs (); err != nil {
414+ log .Printf ("Failed to stop VMs, err: %v\n " , err )
415+ }
416+ orch .Cleanup ()
417+ }
418+ exec .Command ("bash" , "scripts/clean_fcctr.sh" ).Run ()
419+ }
0 commit comments