diff --git a/commandline.c b/commandline.c index ff148aac..e40f1bbd 100644 --- a/commandline.c +++ b/commandline.c @@ -2772,6 +2772,56 @@ int app_reverse_lookup(const struct cli_parsed *parsed, struct cli_context *cont return 1; } +void context_switch_test(int); +int app_mem_test(const struct cli_parsed *parsed, struct cli_context *context) +{ + int mem_size; + int addr; + uint64_t count; + + + // First test context switch speed + context_switch_test(1); + + for(mem_size=1024;mem_size<=(128*1024*1024);mem_size*=2) { + uint8_t *mem=malloc(mem_size); + if (!mem) { + fprintf(stderr,"Could not allocate %dKB memory -- stopping test.\n",mem_size/1024); + return -1; + } + + // Fill memory with random stuff so that we don't have memory page-in + // delays when doing the reads + for(addr=0;addr]","[--duration=|--iterations=]",NULL}, 0, diff --git a/context1.c b/context1.c new file mode 100644 index 00000000..93402c36 --- /dev/null +++ b/context1.c @@ -0,0 +1,103 @@ + +/******************************************************************************* + * The BYTE UNIX Benchmarks - Release 3 + * Module: context1.c SID: 3.3 5/15/91 19:30:18 + * + ******************************************************************************* + * Bug reports, patches, comments, suggestions should be sent to: + * + * Ben Smith, Rick Grehan or Tom Yager + * ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com + * + ******************************************************************************* + * Modification Log: + * $Header: context1.c,v 3.4 87/06/22 14:22:59 kjmcdonell Beta $ + * August 28, 1990 - changed timing routines--now returns total number of + * iterations in specified time period + * October 22, 1997 - code cleanup to remove ANSI C compiler warnings + * Andy Kahn + * + ******************************************************************************/ +char SCCSid[] = "@(#) @(#)context1.c:3.3 -- 5/15/91 19:30:18"; +/* + * Context switching via synchronized unbuffered pipe i/o + * + */ + +#include +#include +#include +#include "timeit.c" + +unsigned long iter; +int stop_timing=0; + +void report() +{ + fprintf(stderr, "%lu context switches per second.\n", iter); + stop_timing=1; +} + +void context_switch_test(int duration) +{ + unsigned long check; + int p1[2], p2[2]; + + + /* set up alarm call */ + iter = 0; + wake_me(duration, report); + + if (pipe(p1) || pipe(p2)) { + perror("pipe create failed"); + exit(1); + } + + if (fork()) { /* parent process */ + /* master, write p1 & read p2 */ + close(p1[0]); close(p2[1]); + while (!stop_timing) { + if (write(p1[1], (char *)&iter, sizeof(iter)) != sizeof(iter)) { + if ((errno != 0) && (errno != EINTR)) + perror("master write failed"); + exit(1); + } + if (read(p2[0], (char *)&check, sizeof(check)) != sizeof(check)) { + if ((errno != 0) && (errno != EINTR)) + perror("master read failed"); + exit(1); + } + if (check != iter) { + fprintf(stderr, "Master sync error: expect %lu, got %lu\n", + iter, check); + exit(2); + } + iter++; + } + } + else { /* child process */ + unsigned long iter1; + + iter1 = 0; + /* slave, read p1 & write p2 */ + close(p1[1]); close(p2[0]); + while (!stop_timing) { + if (read(p1[0], (char *)&check, sizeof(check)) != sizeof(check)) { + if ((errno != 0) && (errno != EINTR)) + perror("slave read failed"); + exit(1); + } + if (check != iter1) { + fprintf(stderr, "Slave sync error: expect %lu, got %lu\n", + iter, check); + exit(2); + } + if (write(p2[1], (char *)&iter1, sizeof(iter1)) != sizeof(check)) { + if ((errno != 0) && (errno != EINTR)) + perror("slave write failed"); + exit(1); + } + iter1++; + } + } +} diff --git a/fakeradio.c b/fakeradio.c index 5727ad1b..b63eff9f 100644 --- a/fakeradio.c +++ b/fakeradio.c @@ -366,12 +366,48 @@ int transfer_bytes(struct radio_state *radios) return bytes; } +int calc_ber(double target_packet_fraction) +{ + int byte_count=220+32; + int max_error_bytes=16; + + int ber; + int p; + int byte; + int bit; + + // 9,000,000 gives a packet delivery rate of ~99% + // so no point starting smaller than that. + // Only ~30,000,000 reduces packet delivery rate to + // ~1%, so the search range is fairly narrow. + ber=9000000; + if (target_packet_fraction<=0.9) ber=13000000; + if (target_packet_fraction<=0.5) ber=18000000; + if (target_packet_fraction<=0.25) ber=21000000; + if (target_packet_fraction<=0.1) ber=24000000; + if (target_packet_fraction<=0.05) ber=26000000; + for(;ber<0x70ffffff;ber+=100000) + { + int packet_errors=0; + for(p=0;p<1000;p++) { + int byte_errors=0; + for(byte=0;bytemax_error_bytes) { packet_errors++; break; } + } + } + if (packet_errors>=((1.0-target_packet_fraction)*1000)) break; + } + fprintf(stderr,"ber magic value=%d\n",ber); + return ber; +} + int main(int argc,char **argv) { if (argv[1]) { chars_per_ms=atol(argv[1]); if (argv[2]) - ber=atol(argv[2]); + ber=calc_ber(atof(argv[2])); } fprintf(stderr, "Sending %d bytes per ms\n", chars_per_ms); fprintf(stderr, "Introducing %f%% bit errors\n", (ber * 100.0) / 0xFFFFFFFF); diff --git a/sourcefiles.mk b/sourcefiles.mk index f4954e22..ddd229f8 100644 --- a/sourcefiles.mk +++ b/sourcefiles.mk @@ -76,4 +76,5 @@ SERVAL_SOURCES = \ $(SERVAL_BASE)fec-3.0.1/ccsds_tables.c \ $(SERVAL_BASE)fec-3.0.1/decode_rs_8.c \ $(SERVAL_BASE)fec-3.0.1/encode_rs_8.c \ - $(SERVAL_BASE)fec-3.0.1/init_rs_char.c + $(SERVAL_BASE)fec-3.0.1/init_rs_char.c \ + $(SERVAL_BASE)context1.c diff --git a/tests/rhizomeprotocol b/tests/rhizomeprotocol index 15e8665f..ff9a58f3 100755 --- a/tests/rhizomeprotocol +++ b/tests/rhizomeprotocol @@ -209,59 +209,6 @@ test_UnicastTransfer() { receive_and_update_bundle } -doc_SimulatedRadio="MDP Transfer over simulated radio link" -interface_up() { - $GREP "Interface .* is up" $instance_servald_log || return 1 - return 0 -} -start_radio_instance() { - executeOk_servald config \ - set debug.rhizome on \ - set debug.rhizome_ads on \ - set debug.rhizome_httpd on \ - set debug.rhizome_tx on \ - set debug.rhizome_rx on \ - set debug.throttling on \ - set debug.mavlink on \ - set rhizome.advertise.interval 5000 \ - set rhizome.rhizome_mdp_block_size 350 \ - set log.console.level debug \ - set log.console.show_pid on \ - set log.console.show_time on \ - set interfaces.1.type CATEAR \ - set interfaces.1.mdp.tick_ms 5000 \ - set interfaces.1.socket_type STREAM \ - set interfaces.1.encapsulation SINGLE \ - set interfaces.1.point_to_point on - start_servald_server - wait_until interface_up -} -setup_SimulatedRadio() { - setup_common - $servald_build_root/fakeradio 6 10000000 > "$SERVALD_VAR/radioout" 2> "$SERVALD_VAR/radioerr" & - FAKERADIO_PID=$! - sleep 1 - local END1=`head "$SERVALD_VAR/radioout" -n 1` - local END2=`tail "$SERVALD_VAR/radioout" -n 1` - tfw_log "Started fakeradio pid=$FAKERADIO_PID, end1=$END1, end2=$END2" - set_instance +A - rhizome_add_file file1 10000 - executeOk_servald config \ - set interfaces.1.file "$END1" - set_instance +B - executeOk_servald config \ - set interfaces.1.file "$END2" - foreach_instance +A +B start_radio_instance -} -test_SimulatedRadio() { - receive_and_update_bundle -} -teardown_SimulatedRadio() { - teardown - tfw_log "Killing fakeradio, pid=$FAKERADIO_PID" - kill $FAKERADIO_PID - tfw_cat "$SERVALD_VAR/radioerr" -} doc_journalMDP="Transfer and update a journal bundle via MDP" setup_journalMDP() { @@ -744,4 +691,86 @@ test_DirectSync() { assert_rhizome_received fileA3 } +interface_up() { + $GREP "Interface .* is up" $instance_servald_log || return 1 + return 0 +} +start_radio_instance() { + executeOk_servald config \ + set debug.rhizome on \ + set debug.rhizome_ads on \ + set debug.rhizome_tx on \ + set debug.rhizome_rx on \ + set debug.throttling on \ + set debug.mavlink on \ + set rhizome.advertise.interval 5000 \ + set rhizome.rhizome_mdp_block_size 350 \ + set log.console.level debug \ + set log.console.show_pid on \ + set log.console.show_time on \ + set interfaces.1.type CATEAR \ + set interfaces.1.mdp.tick_ms 5000 \ + set interfaces.1.socket_type STREAM \ + set interfaces.1.encapsulation SINGLE \ + set interfaces.1.point_to_point on + start_servald_server + wait_until interface_up +} + +doc_SimulatedRadio="MDP Transfer over simulated radio link (~90% packet arrival)" +setup_SimulatedRadio() { + setup_common + $servald_build_root/fakeradio 6 0.9 > "$SERVALD_VAR/radioout" 2> "$SERVALD_VAR/radioerr" & + FAKERADIO_PID=$! + sleep 5 + local END1=`head "$SERVALD_VAR/radioout" -n 1` + local END2=`tail "$SERVALD_VAR/radioout" -n 1` + tfw_log "Started fakeradio pid=$FAKERADIO_PID, end1=$END1, end2=$END2" + set_instance +A + rhizome_add_file file1 10000 + executeOk_servald config \ + set interfaces.1.file "$END1" + set_instance +B + executeOk_servald config \ + set interfaces.1.file "$END2" + foreach_instance +A +B start_radio_instance +} +test_SimulatedRadio() { + receive_and_update_bundle +} +teardown_SimulatedRadio() { + teardown + tfw_log "Killing fakeradio, pid=$FAKERADIO_PID" + kill $FAKERADIO_PID + tfw_cat "$SERVALD_VAR/radioerr" +} + +doc_SimulatedRadio2="MDP Transfer over simulated radio link (~50% packet arrival)" +setup_SimulatedRadio2() { + setup_common + $servald_build_root/fakeradio 6 0.5 > "$SERVALD_VAR/radioout" 2> "$SERVALD_VAR/radioerr" & + FAKERADIO_PID=$! + sleep 1 + local END1=`head "$SERVALD_VAR/radioout" -n 1` + local END2=`tail "$SERVALD_VAR/radioout" -n 1` + tfw_log "Started fakeradio pid=$FAKERADIO_PID, end1=$END1, end2=$END2" + set_instance +A + rhizome_add_file file1 10000 + executeOk_servald config \ + set interfaces.1.file "$END1" + set_instance +B + executeOk_servald config \ + set interfaces.1.file "$END2" + foreach_instance +A +B start_radio_instance +} +test_SimulatedRadio2() { + receive_and_update_bundle +} +teardown_SimulatedRadio2() { + teardown + tfw_log "Killing fakeradio, pid=$FAKERADIO_PID" + kill $FAKERADIO_PID + tfw_cat "$SERVALD_VAR/radioerr" +} + runTests "$@" diff --git a/tests/routing b/tests/routing index 382ecd73..c2966c14 100755 --- a/tests/routing +++ b/tests/routing @@ -265,7 +265,7 @@ setup_simulate_extender() { setup_servald assert_no_servald_processes foreach_instance +A +B create_single_identity - $servald_build_root/fakeradio 1 20000000 > "$SERVALD_VAR/radioout" 2> "$SERVALD_VAR/radioerr" & + $servald_build_root/fakeradio 1 0.8 > "$SERVALD_VAR/radioout" 2> "$SERVALD_VAR/radioerr" & FAKERADIO_PID=$! sleep 1 local END1=`head "$SERVALD_VAR/radioout" -n 1` diff --git a/timeit.c b/timeit.c new file mode 100644 index 00000000..00d1cfce --- /dev/null +++ b/timeit.c @@ -0,0 +1,41 @@ +/******************************************************************************* + * + * The BYTE UNIX Benchmarks - Release 3 + * Module: timeit.c SID: 3.3 5/15/91 19:30:21 + ******************************************************************************* + * Bug reports, patches, comments, suggestions should be sent to: + * + * Ben Smith, Rick Grehan or Tom Yager + * ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com + * + ******************************************************************************* + * Modification Log: + * May 12, 1989 - modified empty loops to avoid nullifying by optimizing + * compilers + * August 28, 1990 - changed timing relationship--now returns total number + * of iterations (ty) + * October 22, 1997 - code cleanup to remove ANSI C compiler warnings + * Andy Kahn + * + ******************************************************************************/ + +/* this module is #included in other modules--no separate SCCS ID */ + +/* + * Timing routine + * + */ + +#include +#include + +void wake_me(seconds, func) + int seconds; + void (*func)(); +{ + /* set up the signal handler */ + signal(SIGALRM, func); + /* get the clock running */ + alarm(seconds); +} + diff --git a/version_string.sh b/version_string.sh index 0a7cd3df..2035ee09 100755 --- a/version_string.sh +++ b/version_string.sh @@ -115,7 +115,11 @@ if [ -n "$dirty" ] && ! $allow_modified; then fi # Use the "git describe" command to form the version string and append $dirty. -if error="$( (desc="$(git describe --match="$version_tag_glob")" && echo "$desc$dirty") 2>&1 1>&5)" 5>&1; then +# This ugly construction is required for use on machines with bash version < 4. +error="$(git describe --match="$version_tag_glob" 2>&1 1>/dev/null)" || true + +if [ -z "$error" ]; then + echo "$(git describe --match="$version_tag_glob")$dirty" exit 0 fi