From 6e17f88f8fbf396a641a5642e4ac17f66d9006f7 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Wed, 12 Apr 2023 19:10:55 -0700 Subject: [PATCH 1/5] link c tests to rust --- program/c/makefile | 17 ++++- program/c/src/oracle/model/test_price_model.c | 5 +- program/c/src/oracle/sort/test_sort_stable.c | 5 +- program/c/src/oracle/util/test_align.c | 4 +- program/c/src/oracle/util/test_avg.c | 5 +- program/c/src/oracle/util/test_hash.c | 5 +- program/c/src/oracle/util/test_prng.c | 5 +- program/c/src/oracle/util/test_round.c | 5 +- program/c/src/oracle/util/test_sar.c | 4 +- program/rust/build.rs | 25 +++++-- program/rust/src/tests/mod.rs | 1 + program/rust/src/tests/test_c_code.rs | 69 +++++++++++++++++++ 12 files changed, 114 insertions(+), 36 deletions(-) create mode 100644 program/rust/src/tests/test_c_code.rs diff --git a/program/c/makefile b/program/c/makefile index 29d6c0260..d1a872a3c 100644 --- a/program/c/makefile +++ b/program/c/makefile @@ -16,7 +16,7 @@ endif # The all target is defined by the solana makefile included above and generates the needed .o file. .PHONY: cpyth-bpf cpyth-bpf: all - bash -c "ar rcs $(OUT_DIR)/libcpyth-bpf.a $(OUT_DIR)/**/*.o" + bash -c "ar rcs $(OUT_DIR)/libcpyth-bpf.a $(OUT_DIR)/oracle/*.o" # 2-Stage Contract Build @@ -27,3 +27,18 @@ cpyth-bpf: all cpyth-native: gcc -c ./src/oracle/native/upd_aggregate.c -o $(OUT_DIR)/cpyth-native.o -fPIC ar rcs $(OUT_DIR)/libcpyth-native.a $(OUT_DIR)/cpyth-native.o + + +# Note: there's probably a smart way to do this with wildcards but I (jayant) can't figure it out +.PHONY: test +test: + mkdir -p $(OUT_DIR)/test/ + gcc -c ./src/oracle/model/test_price_model.c -o $(OUT_DIR)/test/test_price_model.o -fPIC + gcc -c ./src/oracle/sort/test_sort_stable.c -o $(OUT_DIR)/test/test_sort_stable.o -fPIC + gcc -c ./src/oracle/util/test_align.c -o $(OUT_DIR)/test/test_align.o -fPIC + gcc -c ./src/oracle/util/test_avg.c -o $(OUT_DIR)/test/test_avg.o -fPIC + gcc -c ./src/oracle/util/test_hash.c -o $(OUT_DIR)/test/test_hash.o -fPIC + gcc -c ./src/oracle/util/test_prng.c -o $(OUT_DIR)/test/test_prng.o -fPIC + gcc -c ./src/oracle/util/test_round.c -o $(OUT_DIR)/test/test_round.o -fPIC + gcc -c ./src/oracle/util/test_sar.c -o $(OUT_DIR)/test/test_sar.o -fPIC + ar rcs $(OUT_DIR)/libcpyth-test.a $(OUT_DIR)/test/*.o diff --git a/program/c/src/oracle/model/test_price_model.c b/program/c/src/oracle/model/test_price_model.c index 06038d8e6..13359d63a 100644 --- a/program/c/src/oracle/model/test_price_model.c +++ b/program/c/src/oracle/model/test_price_model.c @@ -14,10 +14,7 @@ qcmp( void const * _p, return 0; } -int -main( int argc, - char ** argv ) { - (void)argc; (void)argv; +int test_price_model() { prng_t _prng[1]; prng_t * prng = prng_join( prng_new( _prng, (uint32_t)0, (uint64_t)0 ) ); diff --git a/program/c/src/oracle/sort/test_sort_stable.c b/program/c/src/oracle/sort/test_sort_stable.c index dc620a0d8..e6543e53b 100644 --- a/program/c/src/oracle/sort/test_sort_stable.c +++ b/program/c/src/oracle/sort/test_sort_stable.c @@ -9,10 +9,7 @@ #define SORT_BEFORE(i,j) BEFORE(i,j) #include "tmpl/sort_stable.c" -int -main( int argc, - char ** argv ) { - (void)argc; (void)argv; +int test_sort_stable() { # define N 96 int x[N]; diff --git a/program/c/src/oracle/util/test_align.c b/program/c/src/oracle/util/test_align.c index f958c89f2..5a06895a1 100644 --- a/program/c/src/oracle/util/test_align.c +++ b/program/c/src/oracle/util/test_align.c @@ -3,9 +3,7 @@ #include "util.h" int -main( int argc, - char ** argv ) { - (void)argc; (void)argv; +test_align() { uint32_t shift_mask = (uint32_t)(sizeof(uintptr_t)*(size_t)CHAR_BIT); if( !align_ispow2( (uintptr_t)shift_mask ) ) { diff --git a/program/c/src/oracle/util/test_avg.c b/program/c/src/oracle/util/test_avg.c index 98f4f2502..e5783218c 100644 --- a/program/c/src/oracle/util/test_avg.c +++ b/program/c/src/oracle/util/test_avg.c @@ -2,10 +2,7 @@ #include "util.h" int -main( int argc, - char ** argv ) { - (void)argc; (void)argv; - +test_avg() { prng_t _prng[1]; prng_t * prng = prng_join( prng_new( _prng, (uint32_t)0, (uint64_t)0 ) ); diff --git a/program/c/src/oracle/util/test_hash.c b/program/c/src/oracle/util/test_hash.c index ce39b1e80..5a12a148b 100644 --- a/program/c/src/oracle/util/test_hash.c +++ b/program/c/src/oracle/util/test_hash.c @@ -28,10 +28,7 @@ uint64_t ref64[10] = { UINT64_C( 0x91209a1ff7f4f1d5 ) }; -int -main( int argc, - char ** argv ) { - (void)argc; (void)argv; +int test_hash() { for( int i=0; i<10; i++ ) { uint32_t x = (uint32_t)i; diff --git a/program/c/src/oracle/util/test_prng.c b/program/c/src/oracle/util/test_prng.c index d5a9ccafa..1074b8d1e 100644 --- a/program/c/src/oracle/util/test_prng.c +++ b/program/c/src/oracle/util/test_prng.c @@ -42,10 +42,7 @@ printf_ref( uint64_t * ref, printf( "};\n" ); } -int -main( int argc, - char ** argv ) { - (void)argc; (void)argv; +int test_prng() { uint64_t x[10]; diff --git a/program/c/src/oracle/util/test_round.c b/program/c/src/oracle/util/test_round.c index c9326d832..a7b6d7396 100644 --- a/program/c/src/oracle/util/test_round.c +++ b/program/c/src/oracle/util/test_round.c @@ -1,10 +1,7 @@ #include int -main( int argc, - char ** argv ) { - (void)argc; (void)argv; - +test_round() { unsigned i = (unsigned)0; int ctr = 0; diff --git a/program/c/src/oracle/util/test_sar.c b/program/c/src/oracle/util/test_sar.c index 88366fb2c..f02666f96 100644 --- a/program/c/src/oracle/util/test_sar.c +++ b/program/c/src/oracle/util/test_sar.c @@ -2,9 +2,7 @@ #include "util.h" int -main( int argc, - char ** argv ) { - (void)argc; (void)argv; +test_sar() { prng_t _prng[1]; prng_t * prng = prng_join( prng_new( _prng, (uint32_t)0, (uint64_t)0 ) ); diff --git a/program/rust/build.rs b/program/rust/build.rs index fa632b0a3..a6c9c8d40 100644 --- a/program/rust/build.rs +++ b/program/rust/build.rs @@ -21,17 +21,27 @@ fn main() { let out_dir = std::env::var("OUT_DIR").unwrap(); let out_dir = PathBuf::from(out_dir); + let mut make_targets = vec![]; + if target_arch == "bpf" { + make_targets.push("cpyth-bpf"); + } else { + make_targets.push("cpyth-native"); + } + + let is_test = true; + if is_test { + make_targets.push("test"); + } + println!("cargo:warning={}", cfg!(test)); + + // We must forward OUT_DIR as an env variable to the make script otherwise it will output // its artifacts to the wrong place. std::process::Command::new("make") .env("VERBOSE", "1") .env("OUT_DIR", out_dir.display().to_string()) .current_dir("../c") - .args([if target_arch == "bpf" { - "cpyth-bpf" - } else { - "cpyth-native" - }]) + .args(make_targets) .status() .expect("Failed to build C program"); @@ -41,8 +51,13 @@ fn main() { } else { println!("cargo:rustc-link-lib=static=cpyth-native"); } + if is_test { + println!("cargo:rustc-link-lib=static=cpyth-test"); + } println!("cargo:rustc-link-search={}", out_dir.display()); + println!("cargo:warning={}", out_dir.display()); + // Generate and write bindings let bindings = Builder::default() .clang_arg(format!("-I{:}", get_solana_inc_path().display())) diff --git a/program/rust/src/tests/mod.rs b/program/rust/src/tests/mod.rs index bcf334029..dc57920cf 100644 --- a/program/rust/src/tests/mod.rs +++ b/program/rust/src/tests/mod.rs @@ -4,6 +4,7 @@ mod test_add_price; mod test_add_product; mod test_add_publisher; mod test_aggregation; +mod test_c_code; mod test_del_price; mod test_del_product; mod test_del_publisher; diff --git a/program/rust/src/tests/test_c_code.rs b/program/rust/src/tests/test_c_code.rs new file mode 100644 index 000000000..914b884b1 --- /dev/null +++ b/program/rust/src/tests/test_c_code.rs @@ -0,0 +1,69 @@ +mod c { + #[link(name = "cpyth-test")] + extern "C" { + pub fn test_price_model() -> i32; + pub fn test_sort_stable() -> i32; + pub fn test_align() -> i32; + pub fn test_avg() -> i32; + pub fn test_hash() -> i32; + pub fn test_prng() -> i32; + pub fn test_round() -> i32; + pub fn test_sar() -> i32; + } +} + +#[test] +fn test_price_model() { + unsafe { + assert_eq!(c::test_price_model(), 0); + } +} + +#[test] +fn test_sort_stable() { + unsafe { + assert_eq!(c::test_sort_stable(), 0); + } +} + +#[test] +fn test_align() { + unsafe { + assert_eq!(c::test_align(), 0); + } +} + +#[test] +fn test_avg() { + unsafe { + assert_eq!(c::test_avg(), 0); + } +} + +#[test] +fn test_hash() { + unsafe { + assert_eq!(c::test_hash(), 0); + } +} + +#[test] +fn test_prng() { + unsafe { + assert_eq!(c::test_prng(), 0); + } +} + +#[test] +fn test_round() { + unsafe { + assert_eq!(c::test_round(), 0); + } +} + +#[test] +fn test_sar() { + unsafe { + assert_eq!(c::test_sar(), 0); + } +} From fdfb9e8c60a42a722c038790ca0e025a77566309 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Wed, 12 Apr 2023 19:12:24 -0700 Subject: [PATCH 2/5] cleanup --- program/rust/build.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/program/rust/build.rs b/program/rust/build.rs index a6c9c8d40..a4ab31024 100644 --- a/program/rust/build.rs +++ b/program/rust/build.rs @@ -27,12 +27,7 @@ fn main() { } else { make_targets.push("cpyth-native"); } - - let is_test = true; - if is_test { - make_targets.push("test"); - } - println!("cargo:warning={}", cfg!(test)); + make_targets.push("test"); // We must forward OUT_DIR as an env variable to the make script otherwise it will output @@ -51,13 +46,9 @@ fn main() { } else { println!("cargo:rustc-link-lib=static=cpyth-native"); } - if is_test { - println!("cargo:rustc-link-lib=static=cpyth-test"); - } + println!("cargo:rustc-link-lib=static=cpyth-test"); println!("cargo:rustc-link-search={}", out_dir.display()); - println!("cargo:warning={}", out_dir.display()); - // Generate and write bindings let bindings = Builder::default() .clang_arg(format!("-I{:}", get_solana_inc_path().display())) From fd191cb7916c39bace3c99db535916abe63c6e65 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Wed, 12 Apr 2023 19:28:49 -0700 Subject: [PATCH 3/5] ok --- program/c/src/oracle/model/test_price_model.c | 3 +- program/c/src/oracle/sort/test_sort_stable.c | 6 +- program/c/src/oracle/util/test_align.c | 4 +- program/c/src/oracle/util/test_avg.c | 10 +- program/c/src/oracle/util/test_hash.c | 2 - program/c/src/oracle/util/test_prng_battery.c | 91 ------------------- program/c/src/oracle/util/test_round.c | 3 +- program/c/src/oracle/util/test_sar.c | 6 +- program/rust/src/tests/test_c_code.rs | 3 + 9 files changed, 13 insertions(+), 115 deletions(-) delete mode 100644 program/c/src/oracle/util/test_prng_battery.c diff --git a/program/c/src/oracle/model/test_price_model.c b/program/c/src/oracle/model/test_price_model.c index 13359d63a..3c899dc52 100644 --- a/program/c/src/oracle/model/test_price_model.c +++ b/program/c/src/oracle/model/test_price_model.c @@ -28,7 +28,7 @@ int test_price_model() { int ctr = 0; for( int iter=0; iter<10000000; iter++ ) { - if( !ctr ) { printf( "Completed %u iterations\n", iter ); ctr = 100000; } + if( !ctr ) { ctr = 100000; } ctr--; /* Generate a random test */ @@ -60,6 +60,5 @@ int test_price_model() { prng_delete( prng_leave( prng ) ); - printf( "pass\n" ); return 0; } diff --git a/program/c/src/oracle/sort/test_sort_stable.c b/program/c/src/oracle/sort/test_sort_stable.c index e6543e53b..3cee637ba 100644 --- a/program/c/src/oracle/sort/test_sort_stable.c +++ b/program/c/src/oracle/sort/test_sort_stable.c @@ -20,7 +20,6 @@ int test_sort_stable() { additional information in the keys to validate stability as well). */ for( int n=0; n<=24; n++ ) { - printf( "Zero-One: Testing n=%i\n", n ); for( long b=0L; b<(1L<>i) & 1L))<<16) | i; for( int i=0; i -#include -#include /* Assumes TestU01 install include directory is in the include search path */ -#include "util.h" - -static double -test_GetU01( void * param, - void * state ) { - (void)param; - return 2.3283064365386962890625e-10 /* 2^-32, exact */ * (double)prng_uint32( (prng_t *)state ); -} - -static unsigned long -test_GetBits( void * param, - void * state ) { - (void)param; - return (unsigned long)prng_uint32( (prng_t *)state ); -} - -static void -test_Write( void * state ) { - prng_t * prng = (prng_t *)state; - printf( "prng(0x%08lxU,0x%016lxUL)\n", (unsigned long)prng_seq( prng ), (unsigned long)prng_idx( prng ) ); -} - -static void -usage( char const * cmd ) { - fprintf( stderr, - "Usage: %s [bat] [seq] [idx]\n" - "\tbat 0 - FIPS-140.2 (fast)\n" - "\tbat 1 - Pseudo-DIEHARD (fast)\n" - "\tbat 2 - TestU01 SmallCrush (fast)\n" - "\tbat 3 - TestU01 Crush (~20 minutes)\n" - "\tbat 4 - TestU01 BigCrush (several hours)\n" - "Note that when running a test in a battery, the probability of it failing even\n" - "though the generator is fine is roughly 0.2%%. Thus, when repeatedly running\n" - "batteries that themselves contain a large number of tests, some test failures\n" - "are expected. So long as the test failures are are sporadic, don't occur in the\n" - "same place when running multiple times with random seq and/or idx, and don't\n" - "have p-values improbably close to 0 (p <<< 1/overall_num_tests_run) or 1\n" - "(1-p <<< 1/overall_num_tests_run), it is expected and normal\n", - cmd ); -} - -int -main( int argc, - char ** argv ) { - - /* Get command line arguments */ - - if( argc!=4 ) { usage( argv[0] ); return 1; } - int bat = atoi( argv[1] ); - uint32_t seq = (uint32_t)strtoul( argv[2], NULL, 0 ); - uint64_t idx = (uint64_t)strtoul( argv[3], NULL, 0 ); - - /* Create the test generator */ - - prng_t _prng[1]; - prng_t * prng = prng_join( prng_new( _prng, seq, idx ) ); - - /* Run the requested test battery */ - - char name[128]; - sprintf( name, "prng(0x%08lxU,0x%016lxUL)", (unsigned long)prng_seq( prng ), (unsigned long)prng_idx( prng ) ); - - unif01_Gen gen[1]; - gen->state = prng; - gen->param = NULL; - gen->name = name; - gen->GetU01 = test_GetU01; - gen->GetBits = test_GetBits; - gen->Write = test_Write; - - switch( bat ) { - case 0: bbattery_FIPS_140_2( gen ); break; - case 1: bbattery_pseudoDIEHARD( gen ); break; - case 2: bbattery_SmallCrush( gen ); break; - case 3: bbattery_Crush( gen ); break; - case 4: bbattery_BigCrush( gen ); break; -//case 5: bbattery_Rabbit( gen ); break; /* FIXME: NB */ -//case 6: bbattery_Alphabit( gen ); break; /* FIXME: NB/R/S */ -//case 7: bbattery_BlockAlphabit( gen ); break; /* FIXME: NB/R/S */ - default: usage( argv[0] ); return 1; - } - - /* Destroy the test generator */ - - prng_delete( prng_leave( prng ) ); - - return 0; -} diff --git a/program/c/src/oracle/util/test_round.c b/program/c/src/oracle/util/test_round.c index a7b6d7396..e5a702eee 100644 --- a/program/c/src/oracle/util/test_round.c +++ b/program/c/src/oracle/util/test_round.c @@ -7,7 +7,7 @@ test_round() { int ctr = 0; for( int x=-32767; x<=32767; x++ ) { for( int y=-32767; y<=32767; y++ ) { - if( !ctr ) { printf( "Completed %u iterations\n", i ); ctr = 10000000; } + if( !ctr ) { ctr = 10000000; } ctr--; int u = (x+y)>>1; @@ -21,7 +21,6 @@ test_round() { i++; } } - printf( "pass\n" ); return 0; } diff --git a/program/c/src/oracle/util/test_sar.c b/program/c/src/oracle/util/test_sar.c index f02666f96..cf55f05eb 100644 --- a/program/c/src/oracle/util/test_sar.c +++ b/program/c/src/oracle/util/test_sar.c @@ -11,8 +11,8 @@ test_sar() { SAMPLED ALREADY THOUGH FOR 8 AND 16 BIT TYPES) */ int ctr = 0; - for( int i=0; i<1000000000; i++ ) { - if( !ctr ) { printf( "Completed %i iterations\n", i ); ctr = 10000000; } + for( int i=0; i<100000000; i++ ) { + if( !ctr ) { ctr = 10000000; } ctr--; /* These tests assume the unit test platform has arithmetic right @@ -40,7 +40,5 @@ test_sar() { prng_delete( prng_leave( prng ) ); - printf( "pass\n" ); - return 0; } diff --git a/program/rust/src/tests/test_c_code.rs b/program/rust/src/tests/test_c_code.rs index 914b884b1..3bd6a9ac8 100644 --- a/program/rust/src/tests/test_c_code.rs +++ b/program/rust/src/tests/test_c_code.rs @@ -1,3 +1,6 @@ +// This file links the various test_*.c files in the C oracle code so they run via cargo. +// Note that most of these tests are exhaustive (testing almost every possible input/output), so +// they take a minute or so to run. mod c { #[link(name = "cpyth-test")] extern "C" { From 9961eefcd7731f92bdbb81f4db6c7196ef2be217 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Wed, 12 Apr 2023 20:11:23 -0700 Subject: [PATCH 4/5] cleanup --- README.md | 71 ++++++++++++++++------------ docker/Dockerfile | 2 - program/c/src/oracle/model/clean | 2 - program/c/src/oracle/model/run_tests | 14 ------ program/c/src/oracle/sort/clean | 2 - program/c/src/oracle/sort/run_tests | 14 ------ program/c/src/oracle/util/clean | 2 - program/c/src/oracle/util/run_tests | 51 -------------------- scripts/run-aggregation-tests.sh | 11 ----- 9 files changed, 41 insertions(+), 128 deletions(-) delete mode 100755 program/c/src/oracle/model/clean delete mode 100755 program/c/src/oracle/model/run_tests delete mode 100755 program/c/src/oracle/sort/clean delete mode 100755 program/c/src/oracle/sort/run_tests delete mode 100755 program/c/src/oracle/util/clean delete mode 100755 program/c/src/oracle/util/run_tests delete mode 100755 scripts/run-aggregation-tests.sh diff --git a/README.md b/README.md index b69d67a3c..43ec57d55 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,45 @@ # pyth-client -client API for on-chain pyth programs + +Pyth oracle program and off-chain client API. + +## Oracle Program + +The Pyth oracle program lives in the `program/` directory. +It consists of both C and Rust code, but everything can be built and tested using `cargo`. + +### Build Instructions + +First, make sure you have the [solana tool suite](https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-tool) +installed on your machine. (The build depends on some C makefiles that are in the tool suite.) + +Then, simply run `cargo build` to compile the oracle program as a native binary, or `cargo build-bpf` to build a BPF binary +that can be uploaded to the blockchain. This step will produce a program binary `target/deploy/pyth_oracle.so`. + +### Testing + +Simply run `cargo test`. This command will run several sets of tests: + +- Unit tests of individual functions +- Simulated transaction tests against the BPF binary running on a solana simulator +- Exhaustive / randomized test batteries for core oracle functionality + +Rust tests live in the `tests/` module of the rust code, and C tests are named something like `test_*.c`. +The C tests are linked into the rust binary so they run as part of `cargo test` as well (see `tests/test_c_code.rs`). + +You can also run `cargo test-bpf`, which runs the same tests as `cargo test`, though it's slightly slower and the UX is worse. + +### pre-commit hooks +pre-commit is a tool that checks and fixes simple issues (formatting, ...) before each commit. You can install it by following [their website](https://pre-commit.com/). In order to enable checks for this repo run `pre-commit install` from command-line in the root of this repo. + +The checks are also performed in the CI to ensure the code follows consistent formatting. Formatting is only currently enforced in the `program/` directory. +You might also need to install the nightly toolchain to run the formatting by running `rustup toolchain install nightly`. + +## pythd (off-chain client API) + +> :warning: pythd is deprecated and has been replaced by [pyth-agent](https://github.com/pyth-network/pyth-agent). +> This new client is backward compatible with pythd, but more stable and configurable. + +`pythd` provides exposes a web API for interacting with the on-chain oracle program. ### Build Instructions @@ -44,30 +84,6 @@ This command runs a recent pyth-client docker image that already has the necessa Therefore, once the container is running, all you have to do is run `cd pyth-client && ./scripts/build.sh`. Note that updates to the `pyth-client` directory made inside the docker container will be persisted to the host filesystem (which is probably desirable). -### Local development - -First, make sure you're building on the x86_64 architecture. -On a mac, this command will switch your shell to x86_64: - -`env /usr/bin/arch -x86_64 /bin/bash --login` - -then in the `program/c` directory, run: - -``` -make -make cpyth-bpf -make cpyth-native -``` - -then in the `program/rust` directory, run: - -``` -cargo build-bpf -cargo test -``` - -Note that the tests depend on the bpf build! - ### Fuzzing Build a docker image for running fuzz tests: @@ -130,8 +146,3 @@ root@pyth-dev# usermod -u 1002 -g 1004 -s /bin/bash pyth Finally, in docker extension inside VS Code click right and choose "Attach VS Code". If you're using a remote host in VS Code make sure to let this connection be open. -### pre-commit hooks -pre-commit is a tool that checks and fixes simple issues (formatting, ...) before each commit. You can install it by following [their website](https://pre-commit.com/). In order to enable checks for this repo run `pre-commit install` from command-line in the root of this repo. - -The checks are also performed in the CI to ensure the code follows consistent formatting. Formatting is only currently enforced in the `program/` directory. -You might also need to install the nightly toolchain to run the formatting by running `rustup toolchain install nightly`. diff --git a/docker/Dockerfile b/docker/Dockerfile index 5b89a4b8d..f1a7dccaa 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -63,8 +63,6 @@ RUN ./pyth-client/scripts/patch-solana.sh # Build and test the oracle program. RUN cd pyth-client && ./scripts/build-bpf.sh . RUN cd pyth-client && ./scripts/check-size.sh -# Run aggregation logic tests -RUN cd pyth-client && ./scripts/run-aggregation-tests.sh RUN cd pyth-client/pyth && poetry install && poetry run python -m pytest ENTRYPOINT [] diff --git a/program/c/src/oracle/model/clean b/program/c/src/oracle/model/clean deleted file mode 100755 index 2ca7bfcfd..000000000 --- a/program/c/src/oracle/model/clean +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -rm -rfv bin diff --git a/program/c/src/oracle/model/run_tests b/program/c/src/oracle/model/run_tests deleted file mode 100755 index 5c1d4d1dc..000000000 --- a/program/c/src/oracle/model/run_tests +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -./clean || exit 1 -mkdir -pv bin || exit 1 - -CC="gcc -g -Wall -Werror -Wextra -Wconversion -Wstrict-aliasing=2 -Wimplicit-fallthrough=2 -pedantic -D_XOPEN_SOURCE=600 -O2 -march=native -std=c17" - -set -x - -$CC test_price_model.c price_model.c -o bin/test_price_model || exit 1 - -bin/test_price_model || exit 1 - -echo all tests passed diff --git a/program/c/src/oracle/sort/clean b/program/c/src/oracle/sort/clean deleted file mode 100755 index 2ca7bfcfd..000000000 --- a/program/c/src/oracle/sort/clean +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -rm -rfv bin diff --git a/program/c/src/oracle/sort/run_tests b/program/c/src/oracle/sort/run_tests deleted file mode 100755 index 3c0e1b699..000000000 --- a/program/c/src/oracle/sort/run_tests +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -./clean || exit 1 -mkdir -pv bin || exit 1 - -CC="gcc -g -Wall -Werror -Wextra -Wconversion -Wstrict-aliasing=2 -Wimplicit-fallthrough=2 -pedantic -D_XOPEN_SOURCE=600 -O2 -march=native -std=c17" - -set -x - -$CC test_sort_stable.c -o bin/test_sort_stable || exit 1 - -bin/test_sort_stable || exit 1 - -echo all tests passed diff --git a/program/c/src/oracle/util/clean b/program/c/src/oracle/util/clean deleted file mode 100755 index 2ca7bfcfd..000000000 --- a/program/c/src/oracle/util/clean +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -rm -rfv bin diff --git a/program/c/src/oracle/util/run_tests b/program/c/src/oracle/util/run_tests deleted file mode 100755 index f4e858a1c..000000000 --- a/program/c/src/oracle/util/run_tests +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -./clean || exit 1 -mkdir -pv bin || exit 1 - -CC="gcc -g -Wall -Werror -Wextra -Wconversion -Wstrict-aliasing=2 -Wimplicit-fallthrough=2 -pedantic -D_XOPEN_SOURCE=600 -O2 -march=native -std=c17" - -set -x - -$CC test_align.c -o bin/test_align || exit 1 -$CC test_hash.c -o bin/test_hash || exit 1 -$CC test_prng.c -o bin/test_prng || exit 1 # -lm needed if running to gather statistics -$CC test_sar.c -o bin/test_sar || exit 1 -$CC test_round.c -o bin/test_round || exit 1 -$CC test_avg.c -o bin/test_avg || exit 1 - -bin/test_align || exit 1 -bin/test_hash || exit 1 -bin/test_prng || exit 1 -bin/test_sar || exit 1 -bin/test_round || exit 1 -bin/test_avg || exit 1 - -# PRNG batteries - -# Note that when running an individual test in a TestU01 test battery, -# the probability of that test failing even though the generator is fine -# is roughly 0.2%. Thus, when repeatedly running batteries that -# themselves contain a large number of tests, some test failures are -# expected. So long as the test failures are are sporadic, don't occur -# in the same place when running multiple times with random seq and/or -# idx, and don't have p-values improbably close to 0 -# (p<<<1/overall_num_tests_run) or 1 (1-p<<<1/overall_num_tests_run), it -# is expected and normal. Because of this, TestU01 doesn't just fail if -# a handful of test fails ... need to read the reports produced to see -# how well the generator is actually behaving. - -# Point the TESTU01 variable at where TestU01 is installed. Testing -# thus far has been done with TestU01-1.2.3. - -#TESTU01=~/nfs/TestU01 -# -#$CC test_prng_battery.c -o bin/test_prng_battery -I$TESTU01/include $TESTU01/lib/libtestu01.a $TESTU01/lib/libprobdist.a $TESTU01/lib/libmylib.a -lm || exit 1 -# -#bin/test_prng_battery 0 0 0 || exit 1 # FIPS-140.2 (seq 0, idx 0) -#bin/test_prng_battery 1 0 0 || exit 1 # PseudoDiehard (seq 0, idx 0) -#bin/test_prng_battery 2 0 0 || exit 1 # SmallCrush (seq 0, idx 0) -#bin/test_prng_battery 3 0 0 || exit 1 # Crush: Takes >~20 min (seq 0, idx 0) -#bin/test_prng_battery 4 0 0 || exit 1 # BigCrush: Takes >~3 hours (seq 0, idx 0) - -echo all tests passed diff --git a/scripts/run-aggregation-tests.sh b/scripts/run-aggregation-tests.sh deleted file mode 100755 index 9854d9133..000000000 --- a/scripts/run-aggregation-tests.sh +++ /dev/null @@ -1,11 +0,0 @@ -set -eux - -PYTH_DIR=$( cd "${1:-.}" && pwd) -C_DIR="$PYTH_DIR/program/c/" - -cd "${C_DIR}/src/oracle/model" -./run_tests -cd "${C_DIR}/src/oracle/sort" -./run_tests -cd "${C_DIR}/src/oracle/util" -./run_tests \ No newline at end of file From 3caf4f4e85c6b5f81d086a6893d993a85b4974c4 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Thu, 13 Apr 2023 11:58:36 -0700 Subject: [PATCH 5/5] pr comments --- program/c/src/oracle/model/test_price_model.c | 3 --- program/c/src/oracle/sort/test_sort_stable.c | 4 +--- program/c/src/oracle/util/test_align.c | 3 --- program/c/src/oracle/util/test_avg.c | 16 ++++------------ program/c/src/oracle/util/test_round.c | 3 --- program/c/src/oracle/util/test_sar.c | 3 --- 6 files changed, 5 insertions(+), 27 deletions(-) diff --git a/program/c/src/oracle/model/test_price_model.c b/program/c/src/oracle/model/test_price_model.c index 3c899dc52..71b74127a 100644 --- a/program/c/src/oracle/model/test_price_model.c +++ b/program/c/src/oracle/model/test_price_model.c @@ -26,10 +26,7 @@ int test_price_model() { int64_t val [3]; int64_t scratch[N]; - int ctr = 0; for( int iter=0; iter<10000000; iter++ ) { - if( !ctr ) { ctr = 100000; } - ctr--; /* Generate a random test */ diff --git a/program/c/src/oracle/sort/test_sort_stable.c b/program/c/src/oracle/sort/test_sort_stable.c index 3cee637ba..0b7c4cb7d 100644 --- a/program/c/src/oracle/sort/test_sort_stable.c +++ b/program/c/src/oracle/sort/test_sort_stable.c @@ -45,10 +45,7 @@ int test_sort_stable() { prng_t _prng[1]; prng_t * prng = prng_join( prng_new( _prng, (uint32_t)0, (uint64_t)0 ) ); - int ctr = 0; for( int iter=0; iter<10000000; iter++ ) { - if( !ctr ) { ctr = 100000; } - ctr--; int n = (int)(prng_uint32( prng ) % (uint32_t)(N+1)); /* In [0,N], approx uniform IID */ for( int i=0; i>1; int v = (x>>1)+(y>>1); diff --git a/program/c/src/oracle/util/test_sar.c b/program/c/src/oracle/util/test_sar.c index cf55f05eb..3888795f0 100644 --- a/program/c/src/oracle/util/test_sar.c +++ b/program/c/src/oracle/util/test_sar.c @@ -10,10 +10,7 @@ test_sar() { /* FIXME: EXPLICT COVERAGE OF EDGE CASES (PROBABLY STATICALLY FULLY SAMPLED ALREADY THOUGH FOR 8 AND 16 BIT TYPES) */ - int ctr = 0; for( int i=0; i<100000000; i++ ) { - if( !ctr ) { ctr = 10000000; } - ctr--; /* These tests assume the unit test platform has arithmetic right shift for signed integers (and the diagnostic printfs assume that