Skip to content

Commit

Permalink
native_tests: native tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpsiegel committed Apr 24, 2024
1 parent 40dd884 commit 6a99c9a
Show file tree
Hide file tree
Showing 7 changed files with 2,815 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
path = solana
url = https://github.com/firedancer-io/solana.git
branch = v1.16-fd
[submodule "src/runtime-tests/1"]
path = src/runtime-tests/1
url = https://github.com/firedancer-io/firedancer-testbins
6 changes: 6 additions & 0 deletions src/flamenco/runtime/tests/Local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ $(call add-objs,fd_exec_instr_test,fd_flamenco)

$(call make-unit-test,test_exec_instr,test_exec_instr,fd_flamenco fd_funk fd_ballet fd_util,$(SECP256K1_LIBS))
$(call make-shared,libfd_exec_sol_compat.so,fd_exec_sol_compat,fd_flamenco fd_funk fd_ballet fd_util,$(SECP256K1_LIBS))

$(call make-unit-test,test_native_programs,test_native_programs fd_tests,fd_ballet fd_funk fd_util fd_sol_tests fd_flamenco,$(SECP256K1_LIBS))
$(call run-unit-test,test_native_programs)
endif

# TODO: add run-runtime-test-3 to the list of run-runtime-test after big merge is done
Expand All @@ -15,6 +18,9 @@ run-runtime-test: run-runtime-test-1 run-runtime-test-2
run-runtime-test-big: $(OBJDIR)/unit-test/test_native_programs $(OBJDIR)/unit-test/test_runtime $(OBJDIR)/bin/fd_frank_ledger
OBJDIR=$(OBJDIR) src/flamenco/runtime/tests/run_ledger_tests.sh -l bad-incremental2 -s snapshot-262497545-3sFmKsyF32p4V2HMKaM6s2ymCG64NVcjuxYmen1aKky2.tar.zst -i incremental-snapshot-262497545-262507921-Asuwpa3yuxsBZuVwsad41S3QHYejcdTdeNcqSHKbxvG1.tar.zst -p 250 -m 80000000 -e 255312010

run-runtime-native: $(OBJDIR)/unit-test/test_native_programs
OBJDIR=$(OBJDIR) src/flamenco/runtime/tests/run_native_tests.sh

run-runtime-test-1: $(OBJDIR)/unit-test/test_runtime $(OBJDIR)/bin/fd_frank_ledger
OBJDIR=$(OBJDIR) src/flamenco/runtime/tests/run_ledger_tests.sh -t 2 -X 1
OBJDIR=$(OBJDIR) src/flamenco/runtime/tests/run_ledger_tests.sh
Expand Down
95 changes: 95 additions & 0 deletions src/flamenco/runtime/tests/fd_tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#ifndef HEADER_src_ballet_runtime_tests_fd_tests_h
#define HEADER_src_ballet_runtime_tests_fd_tests_h

#include "../fd_runtime.h"
#include <regex.h>
#include "../../features/fd_features.h"

/* Framework for running Solana's native program tests in our runtime */

#pragma GCC diagnostic ignored "-Wpointer-to-int-cast"

#define fd_feature_offset(x) offsetof( fd_features_t, x )

struct fd_executor_test_acc {
fd_pubkey_t pubkey;
ulong lamports;
ulong result_lamports;
ulong data_len;
ulong result_data_len;
const uchar* data;
const uchar* result_data;
uchar executable;
uchar result_executable;
ulong rent_epoch;
ulong result_rent_epoch;
fd_pubkey_t owner;
fd_pubkey_t result_owner;
};
typedef struct fd_executor_test_acc fd_executor_test_acc_t;
#define FD_EXECUTOR_TEST_ACC_FOOTPRINT ( sizeof(fd_executor_test_acc_t) )

struct fd_test_sysvar_cache {
char * clock;
char * epoch_schedule;
char * epoch_rewards;
char * fees;
char * rent;
char * slot_hashes;
char * recent_block_hashes;
char * stake_history;
char * slot_history;
};
typedef struct fd_test_sysvar_cache fd_test_sysvar_cache_t;
#define FD_TEST_SYSVAR_CACHE_FOOTPRINT ( sizeof(fd_test_sysvar_cache_t) )

struct fd_executor_test {
char* test_name;
int test_number;
uint disable_cnt;
uchar *disable_feature;
const char *bt;
fd_pubkey_t program_id;
fd_executor_test_acc_t* accs;
ulong accs_len;
const uchar* raw_tx;
ulong raw_tx_len;
int expected_result;
uint custom_err;
ulong nonce;
fd_test_sysvar_cache_t sysvar_cache;
};
typedef struct fd_executor_test fd_executor_test_t;
#define FD_EXECUTOR_TEST_FOOTPRINT ( sizeof(fd_executor_test_t) )

struct fd_executor_test_suite {
fd_wksp_t * wksp;
fd_funk_t * funk;
fd_blockstore_t * blockstore;
fd_valloc_t valloc;
regex_t filter_ex;
const char * filter;
fd_features_t features;
char ignore_fail[5000];
};
typedef struct fd_executor_test_suite fd_executor_test_suite_t;
#define FD_EXECUTOR_TEST_SUITE_FOOTPRINT ( sizeof(fd_executor_test_suite_t) )

typedef int (* fd_executor_test_fn)( fd_executor_test_suite_t * );

FD_PROTOTYPES_BEGIN

void fd_executor_test_suite_new( fd_executor_test_suite_t* suite );

int fd_executor_run_test(
fd_executor_test_t* test,
fd_executor_test_suite_t* suite) ;

/* Tests defined by test program. Null terminated */

extern fd_executor_test_fn tests[];
extern ulong test_cnt;

FD_PROTOTYPES_END

#endif /* HEADER_src_ballet_runtime_tests_fd_tests_h */
23 changes: 23 additions & 0 deletions src/flamenco/runtime/tests/run_native_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -f

# this assumes the test_runtime has already been built

OBJDIR=${OBJDIR:-build/native/gcc}

set -x

# Running this twice, but whatever
"$OBJDIR"/unit-test/test_native_programs >& native.log

status=$?

if [ $status -ne 0 ]
then
echo 'native test failed'
grep "not_ignored" native.log | tail -20
exit $status
fi

grep "Progress" native.log

echo 'native tests passed'
Loading

0 comments on commit 6a99c9a

Please sign in to comment.