-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This test performs decode and encode on an image file and compares the result with the original file. The test passes if both files are equivalent byte for byte. Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
- Loading branch information
Showing
5 changed files
with
169 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
CC ?= gcc | ||
GO ?= go | ||
CRIU ?= criu | ||
|
||
all: test clean | ||
all: integration-test e2e-test clean | ||
|
||
test: gen-imgs | ||
integration-test: test-imgs crit-test | ||
@echo "Running integration test" | ||
@./crit-test | ||
|
||
e2e-test: ../../crit/bin/crit test-imgs crit-test.sh | ||
@echo "Running E2E test" | ||
@./crit-test.sh | ||
|
||
gen-imgs: loop | ||
$(eval PID := $(shell ./loop)) | ||
criu dump -v4 -o dump.log -D ./ -t $(PID) | ||
test-imgs: ../loop/loop | ||
$(eval PID := $(shell ../loop/loop)) | ||
mkdir -p $@ | ||
$(CRIU) dump -v4 -o dump.log -D $@ -t $(PID) | ||
|
||
../../crit/bin/crit: | ||
$(MAKE) -C ../../crit bin/crit | ||
|
||
loop: loop.c | ||
../loop/loop: ../loop/loop.c | ||
$(CC) $^ -o $@ | ||
|
||
crit-test: main.go | ||
$(GO) build -v -o $@ $^ | ||
|
||
clean: | ||
@rm -f *.img *.log *.json stats-* | ||
@rm -rf test-imgs | ||
|
||
.PHONY: all test gen-imgs clean | ||
.PHONY: all test integration-test e2e-test clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/checkpoint-restore/go-criu/v5/crit" | ||
) | ||
|
||
const TEST_IMG_DIR = "test-imgs" | ||
|
||
func main() { | ||
// Get list of image files | ||
imgs, err := getImgs() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
// Run recode test | ||
if err = recodeImgs(imgs); err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Println("=== PASS") | ||
} | ||
|
||
func recodeImgs(imgs []string) error { | ||
for _, img := range imgs { | ||
log.Println("===", img) | ||
testImg := fmt.Sprintf("%s.test.img", img) | ||
c := crit.New(img, testImg, "", false, false) | ||
// Decode the binary image file | ||
decodedImg, err := c.Decode() | ||
if err != nil { | ||
return errors.New(fmt.Sprint("[DECODE]: ", err)) | ||
} | ||
// Encode it into test binary image file | ||
if err = c.Encode(decodedImg); err != nil { | ||
return errors.New(fmt.Sprint("[ENCODE]: ", err)) | ||
} | ||
// Open and compare original and test files | ||
imgBytes, err := os.ReadFile(img) | ||
if err != nil { | ||
return err | ||
} | ||
testImgBytes, err := os.ReadFile(testImg) | ||
if err != nil { | ||
return err | ||
} | ||
if !bytes.Equal(imgBytes, testImgBytes) { | ||
return errors.New(fmt.Sprint("[RECODE]: Files do not match")) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func getImgs() ([]string, error) { | ||
// Certain image files generated by CRIU do not | ||
// use the protobuf format and contain raw binary | ||
// data. Some image files are also generated using | ||
// external tools (ifaddr, route, tmpfs). As these | ||
// images cannot be processed by CRIT, they are | ||
// excluded from the tests. | ||
var skipImgs = []string{ | ||
"pages-", | ||
"pages-shmem-", | ||
"iptables-", | ||
"ip6tables-", | ||
"nftables-", | ||
"route-", | ||
"route6-", | ||
"ifaddr-", | ||
"tmpfs-", | ||
"tmpfs-dev-", | ||
"autofs-", | ||
"netns-ct-", | ||
"netns-exp-", | ||
"rule-", | ||
} | ||
// "*.test.img", "*.json.img" or "tmp.*.img" files | ||
// must be skipped as they are generated by tests | ||
criuImg := regexp.MustCompile(`^[^\.]*\.img$`) | ||
dir, err := filepath.Glob(fmt.Sprintf("%s/*.img", TEST_IMG_DIR)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var imgs []string | ||
|
||
nextFile: | ||
for _, file := range dir { | ||
if filepath.Ext(file) == ".img" { | ||
if !criuImg.MatchString(file) { | ||
continue | ||
} | ||
for _, skip := range skipImgs { | ||
if strings.HasPrefix(filepath.Base(file), skip) { | ||
continue nextFile | ||
} | ||
} | ||
imgs = append(imgs, file) | ||
} | ||
} | ||
|
||
return imgs, nil | ||
} |
File renamed without changes.