mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Add a -focus flag.
This commit is contained in:
1 parent
e3643574d7
commit
1487da7af8
7 files changed
+184
-94
No files matched your search
@@ -50,4 +50,15 @@ func main1() error {
|
||||
const (
|
||||
ccompilersDefault = "clang,gcc"
|
||||
ccompilersUsage = `comma-separated list of C compilers, e.g. "clang,gcc"`
|
||||
|
||||
focusDefault = ""
|
||||
focusUsage = `comma-separated list of tests or benchmarks to focus on, e.g. "bench_puffs_gif_decode_10k"`
|
||||
|
||||
mimicDefault = false
|
||||
mimicUsage = `whether to compare Puffs' output with other libraries' output`
|
||||
|
||||
repsDefault = 5
|
||||
repsMin = 0
|
||||
repsMax = 1000000
|
||||
repsUsage = `the number of repetitions per benchmark`
|
||||
)
|
||||
+26
-13
@@ -25,36 +25,46 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isStringList(s string) bool {
|
||||
for i := 0; i < len(s); i++ {
|
||||
c := s[i]
|
||||
if c == ',' || c == '-' || c == '.' || ('0' <= c && c <= '9') || c == '_' || ('a' <= c && c <= 'z') {
|
||||
continue
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func doBench(args []string) error { return doBenchTest(args, true) }
|
||||
func doTest(args []string) error { return doBenchTest(args, false) }
|
||||
|
||||
func doBenchTest(args []string, bench bool) error {
|
||||
const (
|
||||
mimicDefault = false
|
||||
mimicUsage = `whether to compare Puffs' output with other libraries' output`
|
||||
|
||||
repsDefault = 5
|
||||
repsMin = 0
|
||||
repsMax = 1000000
|
||||
repsUsage = `the number of repetitions per benchmark`
|
||||
)
|
||||
|
||||
flags := flag.FlagSet{}
|
||||
ccompilersFlag := flags.String("ccompilers", ccompilersDefault, ccompilersUsage)
|
||||
focusFlag := flags.String("focus", focusDefault, focusUsage)
|
||||
mimicFlag := flags.Bool("mimic", mimicDefault, mimicUsage)
|
||||
repsFlag := flags.Int("reps", repsDefault, repsUsage)
|
||||
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
args = flags.Args()
|
||||
|
||||
if !isStringList(*ccompilersFlag) {
|
||||
return fmt.Errorf("bad -ccompilers flag value %q", *ccompilersFlag)
|
||||
}
|
||||
if !isStringList(*focusFlag) {
|
||||
return fmt.Errorf("bad -focus flag value %q", *focusFlag)
|
||||
}
|
||||
if *repsFlag < repsMin || repsMax < *repsFlag {
|
||||
return fmt.Errorf("bad -reps flag value %d, outside the range [%d..%d]", *repsFlag, repsMin, repsMax)
|
||||
}
|
||||
|
||||
args = flags.Args()
|
||||
|
||||
failed := false
|
||||
for _, arg := range args {
|
||||
f, err := doBenchTest1(arg, bench, *ccompilersFlag, *mimicFlag, *repsFlag)
|
||||
f, err := doBenchTest1(arg, bench, *ccompilersFlag, *focusFlag, *mimicFlag, *repsFlag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -70,7 +80,7 @@ func doBenchTest(args []string, bench bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func doBenchTest1(filename string, bench bool, ccompilers string, mimic bool, reps int) (failed bool, err error) {
|
||||
func doBenchTest1(filename string, bench bool, ccompilers string, focus string, mimic bool, reps int) (failed bool, err error) {
|
||||
workDir, err := ioutil.TempDir("", "puffs-c")
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -113,6 +123,9 @@ func doBenchTest1(filename string, bench bool, ccompilers string, mimic bool, re
|
||||
if bench {
|
||||
outArgs = append(outArgs, "-bench", fmt.Sprintf("-reps=%d", reps))
|
||||
}
|
||||
if focus != "" {
|
||||
outArgs = append(outArgs, fmt.Sprintf("-focus=%s", focus))
|
||||
}
|
||||
outCmd := exec.Command(out, outArgs...)
|
||||
outCmd.Stdout = os.Stdout
|
||||
outCmd.Stderr = os.Stderr
|
||||
|
||||
@@ -121,6 +121,9 @@ const (
|
||||
ccompilersDefault = "clang,gcc"
|
||||
ccompilersUsage = `comma-separated list of C compilers, e.g. "clang,gcc"`
|
||||
|
||||
focusDefault = ""
|
||||
focusUsage = `comma-separated list of tests or benchmarks to focus on, e.g. "bench_puffs_gif_decode_10k"`
|
||||
|
||||
langsDefault = "c"
|
||||
langsUsage = `comma-separated list of target languages (file extensions), e.g. "c,go,rs"`
|
||||
|
||||
|
||||
+25
-1
@@ -23,26 +23,47 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isStringList(s string) bool {
|
||||
for i := 0; i < len(s); i++ {
|
||||
c := s[i]
|
||||
if c == ',' || c == '-' || c == '.' || ('0' <= c && c <= '9') || c == '_' || ('a' <= c && c <= 'z') {
|
||||
continue
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func doBench(puffsRoot string, args []string) error { return doBenchTest(puffsRoot, args, true) }
|
||||
func doTest(puffsRoot string, args []string) error { return doBenchTest(puffsRoot, args, false) }
|
||||
|
||||
func doBenchTest(puffsRoot string, args []string, bench bool) error {
|
||||
flags := flag.NewFlagSet("test", flag.ExitOnError)
|
||||
ccompilersFlag := flags.String("ccompilers", ccompilersDefault, ccompilersUsage)
|
||||
focusFlag := flags.String("focus", focusDefault, focusUsage)
|
||||
langsFlag := flags.String("langs", langsDefault, langsUsage)
|
||||
mimicFlag := flags.Bool("mimic", mimicDefault, mimicUsage)
|
||||
repsFlag := flags.Int("reps", repsDefault, repsUsage)
|
||||
skipgenFlag := flags.Bool("skipgen", skipgenDefault, skipgenUsage)
|
||||
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
langs, err := parseLangs(*langsFlag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !isStringList(*ccompilersFlag) {
|
||||
return fmt.Errorf("bad -ccompilers flag value %q", *ccompilersFlag)
|
||||
}
|
||||
if !isStringList(*focusFlag) {
|
||||
return fmt.Errorf("bad -focus flag value %q", *focusFlag)
|
||||
}
|
||||
if *repsFlag < repsMin || repsMax < *repsFlag {
|
||||
return fmt.Errorf("bad -reps flag value %d, outside the range [%d..%d]", *repsFlag, repsMin, repsMax)
|
||||
}
|
||||
|
||||
args = flags.Args()
|
||||
if len(args) == 0 {
|
||||
args = []string{"std/..."}
|
||||
@@ -54,6 +75,9 @@ func doBenchTest(puffsRoot string, args []string, bench bool) error {
|
||||
} else {
|
||||
cmdArgs = append(cmdArgs, "test")
|
||||
}
|
||||
if *focusFlag != "" {
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("-focus=%s", *focusFlag))
|
||||
}
|
||||
if *mimicFlag {
|
||||
cmdArgs = append(cmdArgs, "-mimic")
|
||||
}
|
||||
@@ -137,7 +161,7 @@ func (b *btHelper) benchTestDir(dirname string) (failed bool, err error) {
|
||||
args := []string(nil)
|
||||
args = append(args, b.cmdArgs...)
|
||||
if lang == "c" {
|
||||
args = append(args, "-ccompilers", b.ccompilers)
|
||||
args = append(args, fmt.Sprintf("-ccompilers=%s", b.ccompilers))
|
||||
}
|
||||
args = append(args, filepath.Join(b.puffsRoot, "test", lang, filepath.FromSlash(dirname)))
|
||||
cmd := exec.Command(command, args...)
|
||||
|
||||
+45
-45
@@ -121,7 +121,7 @@ golden_test zlib_pi_gt = {
|
||||
// ---------------- Checksum Tests
|
||||
|
||||
void test_puffs_adler32() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
struct {
|
||||
const char* filename;
|
||||
@@ -251,53 +251,53 @@ const char* puffs_zlib_decode(puffs_base__buf1* dst,
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_256_bytes() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_256_bytes_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_flate_backref_crosses_blocks() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_flate_backref_crosses_blocks_gt,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_midsummer() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi_many_big_reads() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 0, 4096);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi_many_medium_reads() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 0, 599);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi_many_small_writes_reads() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 59, 61);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_romeo() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_romeo_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_romeo_fixed() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_romeo_fixed_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_split_src() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
@@ -394,7 +394,7 @@ bool do_test_puffs_flate_history(int i,
|
||||
}
|
||||
|
||||
void test_puffs_flate_history_full() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
@@ -450,7 +450,7 @@ void test_puffs_flate_history_full() {
|
||||
}
|
||||
|
||||
void test_puffs_flate_history_partial() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
@@ -509,7 +509,7 @@ void test_puffs_flate_history_partial() {
|
||||
}
|
||||
|
||||
void test_puffs_flate_table_redirect() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
// Call init_huff with a Huffman code that looks like:
|
||||
//
|
||||
@@ -641,7 +641,7 @@ void test_puffs_flate_table_redirect() {
|
||||
}
|
||||
|
||||
void test_puffs_zlib_checksum_mismatch() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
@@ -673,12 +673,12 @@ void test_puffs_zlib_checksum_mismatch() {
|
||||
}
|
||||
|
||||
void test_puffs_zlib_decode_midsummer() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_zlib_decode, &zlib_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_zlib_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_zlib_decode, &zlib_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
@@ -689,53 +689,53 @@ void test_puffs_zlib_decode_pi() {
|
||||
#include "../mimiclib/flate.c"
|
||||
|
||||
void test_mimic_flate_decode_256_bytes() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_256_bytes_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_flate_decode_flate_backref_crosses_blocks() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_flate_backref_crosses_blocks_gt,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_flate_decode_midsummer() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_flate_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_flate_decode_romeo() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_romeo_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_flate_decode_romeo_fixed() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_romeo_fixed_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_gzip_decode_midsummer() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(mimic_gzip_decode, &gzip_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_gzip_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(mimic_gzip_decode, &gzip_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_zlib_decode_midsummer() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(mimic_zlib_decode, &zlib_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_zlib_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(mimic_zlib_decode, &zlib_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
@@ -762,42 +762,42 @@ const char* puffs_bench_adler32(puffs_base__buf1* dst,
|
||||
}
|
||||
|
||||
void bench_puffs_adler32_10k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_bench_adler32, tc_src, &checksum_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_puffs_adler32_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_bench_adler32, tc_src, &checksum_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
// ---------------- Flate Benches
|
||||
|
||||
void bench_puffs_flate_decode_1k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_romeo_gt, 0, 0, 200000);
|
||||
}
|
||||
|
||||
void bench_puffs_flate_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_puffs_flate_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
void bench_puffs_zlib_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_zlib_decode, tc_dst, &zlib_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_puffs_zlib_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_zlib_decode, tc_dst, &zlib_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
@@ -806,62 +806,62 @@ void bench_puffs_zlib_decode_100k() {
|
||||
#ifdef PUFFS_MIMIC
|
||||
|
||||
void bench_mimic_adler32_10k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_bench_adler32, tc_src, &checksum_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_mimic_adler32_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_bench_adler32, tc_src, &checksum_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
void bench_mimic_crc32_10k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_bench_crc32, tc_src, &checksum_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_mimic_crc32_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_bench_crc32, tc_src, &checksum_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
void bench_mimic_flate_decode_1k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_flate_decode, tc_dst, &flate_romeo_gt, 0, 0, 200000);
|
||||
}
|
||||
|
||||
void bench_mimic_flate_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_flate_decode, tc_dst, &flate_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_mimic_flate_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_flate_decode, tc_dst, &flate_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
void bench_mimic_gzip_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_gzip_decode, tc_dst, &gzip_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_mimic_gzip_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_gzip_decode, tc_dst, &gzip_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
void bench_mimic_zlib_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_zlib_decode, tc_dst, &zlib_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_mimic_zlib_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(mimic_zlib_decode, tc_dst, &zlib_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
|
||||
+35
-35
@@ -43,7 +43,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
// ---------------- Basic Tests
|
||||
|
||||
void test_basic_bad_argument_out_of_range() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_gif__lzw_decoder dec;
|
||||
puffs_gif__lzw_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
|
||||
@@ -70,7 +70,7 @@ void test_basic_bad_argument_out_of_range() {
|
||||
}
|
||||
|
||||
void test_basic_bad_receiver() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_base__writer1 dst = {0};
|
||||
puffs_base__reader1 src = {0};
|
||||
puffs_gif__status status = puffs_gif__lzw_decoder__decode(NULL, dst, src);
|
||||
@@ -80,7 +80,7 @@ void test_basic_bad_receiver() {
|
||||
}
|
||||
|
||||
void test_basic_initializer_not_called() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_gif__lzw_decoder dec = {{0}};
|
||||
puffs_base__writer1 dst = {0};
|
||||
puffs_base__reader1 src = {0};
|
||||
@@ -92,7 +92,7 @@ void test_basic_initializer_not_called() {
|
||||
}
|
||||
|
||||
void test_basic_puffs_version_bad() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_gif__lzw_decoder dec;
|
||||
puffs_gif__lzw_decoder__initialize(&dec, 0, 0); // 0 is not PUFFS_VERSION.
|
||||
if (dec.private_impl.status != PUFFS_GIF__ERROR_BAD_PUFFS_VERSION) {
|
||||
@@ -103,7 +103,7 @@ void test_basic_puffs_version_bad() {
|
||||
}
|
||||
|
||||
void test_basic_puffs_version_good() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_gif__lzw_decoder dec;
|
||||
puffs_gif__lzw_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
if (dec.private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
@@ -118,7 +118,7 @@ void test_basic_puffs_version_good() {
|
||||
}
|
||||
|
||||
void test_basic_status_is_error() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
if (puffs_gif__status__is_error(PUFFS_GIF__STATUS_OK)) {
|
||||
FAIL("is_error(OK) returned true");
|
||||
return;
|
||||
@@ -138,7 +138,7 @@ void test_basic_status_is_error() {
|
||||
}
|
||||
|
||||
void test_basic_status_strings() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
const char* s0 = puffs_gif__status__string(PUFFS_GIF__STATUS_OK);
|
||||
const char* t0 = "gif: ok";
|
||||
if (strcmp(s0, t0)) {
|
||||
@@ -174,7 +174,7 @@ void test_basic_status_strings() {
|
||||
}
|
||||
|
||||
void test_basic_sub_struct_initializer() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_gif__decoder dec;
|
||||
puffs_gif__decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
if (dec.private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
@@ -296,35 +296,35 @@ bool do_test_puffs_gif_lzw_decode(const char* src_filename,
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_many_big_reads() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
14731, "../../testdata/bricks-gray.indexes",
|
||||
19200, 0, 4096);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_many_small_writes_reads() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
14731, "../../testdata/bricks-gray.indexes",
|
||||
19200, 41, 43);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_bricks_dither() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-dither.indexes.giflzw",
|
||||
14923, "../../testdata/bricks-dither.indexes",
|
||||
19200, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_bricks_nodither() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-nodither.indexes.giflzw",
|
||||
13382, "../../testdata/bricks-nodither.indexes",
|
||||
19200, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/pi.txt.giflzw", 50550,
|
||||
"../../testdata/pi.txt", 100003, 0, 0);
|
||||
}
|
||||
@@ -371,13 +371,13 @@ bool do_bench_puffs_gif_lzw_decode(const char* filename, uint64_t reps) {
|
||||
}
|
||||
|
||||
void bench_puffs_gif_lzw_decode_20k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_puffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
5000);
|
||||
}
|
||||
|
||||
void bench_puffs_gif_lzw_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_puffs_gif_lzw_decode("../../testdata/pi.txt.giflzw", 1000);
|
||||
}
|
||||
|
||||
@@ -504,21 +504,21 @@ bool do_test_puffs_gif_decode(const char* filename,
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes", 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_big_reads() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes", 0, 4096);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_medium_reads() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes", 0,
|
||||
@@ -527,14 +527,14 @@ void test_puffs_gif_decode_input_is_a_gif_many_medium_reads() {
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_small_writes_reads() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes", 11, 13);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_png() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
@@ -596,37 +596,37 @@ bool do_test_mimic_gif_decode(const char* filename) {
|
||||
}
|
||||
|
||||
void test_mimic_gif_decode_bricks_dither() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_mimic_gif_decode("../../testdata/bricks-dither.gif");
|
||||
}
|
||||
|
||||
void test_mimic_gif_decode_bricks_gray() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_mimic_gif_decode("../../testdata/bricks-gray.gif");
|
||||
}
|
||||
|
||||
void test_mimic_gif_decode_bricks_nodither() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_mimic_gif_decode("../../testdata/bricks-nodither.gif");
|
||||
}
|
||||
|
||||
void test_mimic_gif_decode_harvesters() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_mimic_gif_decode("../../testdata/harvesters.gif");
|
||||
}
|
||||
|
||||
void test_mimic_gif_decode_hat() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_mimic_gif_decode("../../testdata/hat.gif");
|
||||
}
|
||||
|
||||
void test_mimic_gif_decode_hibiscus() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_mimic_gif_decode("../../testdata/hibiscus.gif");
|
||||
}
|
||||
|
||||
void test_mimic_gif_decode_pjw_thumbnail() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_mimic_gif_decode("../../testdata/pjw-thumbnail.gif");
|
||||
}
|
||||
|
||||
@@ -663,23 +663,23 @@ bool do_bench_gif_decode(const char* (*decode_func)(puffs_base__buf1*,
|
||||
}
|
||||
|
||||
void bench_puffs_gif_decode_1k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(puffs_gif_decode, "../../testdata/pjw-thumbnail.gif",
|
||||
200000);
|
||||
}
|
||||
|
||||
void bench_puffs_gif_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(puffs_gif_decode, "../../testdata/hat.gif", 10000);
|
||||
}
|
||||
|
||||
void bench_puffs_gif_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(puffs_gif_decode, "../../testdata/hibiscus.gif", 1000);
|
||||
}
|
||||
|
||||
void bench_puffs_gif_decode_1000k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(puffs_gif_decode, "../../testdata/harvesters.gif", 100);
|
||||
}
|
||||
|
||||
@@ -688,23 +688,23 @@ void bench_puffs_gif_decode_1000k() {
|
||||
#ifdef PUFFS_MIMIC
|
||||
|
||||
void bench_mimic_gif_decode_1k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(mimic_gif_decode, "../../testdata/pjw-thumbnail.gif",
|
||||
200000);
|
||||
}
|
||||
|
||||
void bench_mimic_gif_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(mimic_gif_decode, "../../testdata/hat.gif", 10000);
|
||||
}
|
||||
|
||||
void bench_mimic_gif_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(mimic_gif_decode, "../../testdata/hibiscus.gif", 1000);
|
||||
}
|
||||
|
||||
void bench_mimic_gif_decode_1000k() {
|
||||
proc_funcname = __func__;
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(mimic_gif_decode, "../../testdata/harvesters.gif", 100);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,38 @@ int tests_run = 0;
|
||||
|
||||
const char* proc_filename = "";
|
||||
const char* proc_funcname = "";
|
||||
const char* focus = "";
|
||||
bool in_focus = false;
|
||||
|
||||
#define CHECK_FOCUS(funcname) \
|
||||
proc_funcname = funcname; \
|
||||
in_focus = check_focus(); \
|
||||
if (!in_focus) { \
|
||||
return; \
|
||||
}
|
||||
|
||||
bool check_focus() {
|
||||
const char* p = focus;
|
||||
if (!*p) {
|
||||
return true;
|
||||
}
|
||||
// On each iteration of the loop, set p and q so that p (inclusive) and q
|
||||
// (exclusive) bracket the comma-separated elements of focus.
|
||||
while (true) {
|
||||
const char* q = p;
|
||||
while ((*q != ',') && (*q != '\x00')) {
|
||||
q++;
|
||||
}
|
||||
if (!strncmp(proc_funcname, p, q - p)) {
|
||||
return true;
|
||||
}
|
||||
if (*q == '\x00') {
|
||||
break;
|
||||
}
|
||||
p = q + 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// The order matters here. Clang also defines "__GNUC__".
|
||||
#if defined(__clang__)
|
||||
@@ -114,6 +146,9 @@ int test_main(int argc, char** argv, proc* tests, proc* benches) {
|
||||
if (!strcmp(arg, "-bench")) {
|
||||
bench = true;
|
||||
|
||||
} else if (!strncmp(arg, "-focus=", 7)) {
|
||||
focus = arg + 7;
|
||||
|
||||
} else if (!strncmp(arg, "-reps=", 6)) {
|
||||
arg += 6;
|
||||
if (!*arg) {
|
||||
@@ -158,7 +193,11 @@ int test_main(int argc, char** argv, proc* tests, proc* benches) {
|
||||
proc* p;
|
||||
for (p = procs; *p; p++) {
|
||||
proc_funcname = "unknown_funcname";
|
||||
in_focus = false;
|
||||
(*p)();
|
||||
if (!in_focus) {
|
||||
continue;
|
||||
}
|
||||
if (fail_msg[0]) {
|
||||
printf("%-16s%-8sFAIL %s: %s\n", proc_filename, cc, proc_funcname,
|
||||
fail_msg);
|
||||
|
||||
Reference in new issue
Block a user