Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
test
#tclsh 8.6 #============================== L2* MOCK FUNCTIONS ========================================================================================== namespace eval L2TSEQ { proc ::L2TSEQ::begin {name arguments {precision MILLISECOND}} {} proc ::L2TSEQ::end {{mode AUTOMATIC}} {} } namespace eval L2UTIL { proc ::L2UTIL::print {message {severity INFO}} { puts $message } } #============================== PLANNING ID FUNCTION ========================================================================================== namespace eval L3nisp_fm_hlib { # ##################################################################################################################################### # Subroutine: ::L3nisp_fm_hlib::planning_id # This subroutine automatically evaluate the planning id according to "PlanningID_is3.1.pdf" Jan/2019 # # Parameters: # temp_case - shall be WARM or COLD # test_case - shall be SFT, FFT or EXPO # unique_id - shall be integer \[0,255\] if EXPO or \[0,127] if SFT(FFT) # led_id - shall be LED#1, LED#2, LED#3, LED#4, LED#5 or NONE # led_flux_id - shall be integer \[0,7\] (ignored and set to 0 if led_id = NONE) # cycle_or_subcase - shall be integer \[0,4095\] # dither - shall be integer \[0,15\] # # Examples: # > ::L3nisp_fm_hlib::planning_id WARM FFT 34 LED#2 4 2056 6 # > [::L3nisp_fm_hlib::planning_id $::L3nisp_common::environmental_config SFT 1 NONE 0 1 1] # # Return: # - the planningID or "0xFFFFFFFF" in case of parameters out of bounds or invalid # # ###################################################################################################################################### proc ::L3nisp_fm_hlib::planning_id {temp_case test_type unique_id led_id led_flux_id cycle_or_subcase dither} { # define flags set is_cold [expr 1 << 23] set is_sft [expr 1 << 22] set is_fft [expr (1 << 22) + (1 << 31)] # define bit shifts set type_b 24 set led_b 19 set cycle_b 4 set flux_b 16 # parse arguments set p 0 set err_message "" # - temp_case switch $temp_case { WARM {} COLD {incr p $is_cold} default {append err_message "\n - temp_case ($temp_case) shall be WARM or COLD"} } # - test_type set unique_id_max 127 switch $test_type { SFT {incr p $is_sft} FFT {incr p $is_fft} EXPO {set unique_id_max 255} default {append err_message "\n - test_type ($test_type) shall be SFT, FFT or EXPO"} } # - test_id if {![string is integer -strict $unique_id] || $unique_id < 0 || $unique_id > $unique_id_max } { append err_message "\n - unique_id ($unique_id) shall be integer \[0,$unique_id_max\]" } # - led_id switch $led_id { NONE { } LED#1 {incr p [expr (1 << $led_b)]} LED#2 {incr p [expr (2 << $led_b)]} LED#3 {incr p [expr (3 << $led_b)]} LED#4 {incr p [expr (4 << $led_b)]} LED#5 {incr p [expr (5 << $led_b)]} default { append err_message "\n - led_id ($led_id) shall be LED#1, LED#2, LED#3, LED#4, LED#5 or NONE"} } # - led_flux_id if {![string is integer -strict $led_flux_id] || $led_flux_id < 0 || $led_flux_id > 7 } { append err_message "\n - led_flux_id ($led_flux_id) shall be integer \[0,7\]" } if {$led_id == "NONE"} { set led_flux_id 0 } # - cycle_or_subcase if {![string is integer -strict $cycle_or_subcase] || $cycle_or_subcase < 0 || $cycle_or_subcase > 4095} { append err_message "\n - cycle_or_subcase ($cycle_or_subcase) shall be integer \[0,4095\]" } # - dither if {![string is integer -strict $dither] || $dither < 0 || $dither > 15} { append err_message "\n - dither ($dither) shall be integer \[0,15\]" } # manage error if {$err_message != ""} { ::L2UTIL::print "WARNING: cannot compute the planning ID: $err_message" WARN return 0xFFFFFFFF; } incr p [expr ($unique_id << $type_b) + ($led_flux_id << $flux_b) + ($cycle_or_subcase << $cycle_b) + $dither] return $p } ;# end of ::L3nisp_fm_hlib::planning_id } #============================== UNIT TEST ========================================================================================== namespace eval ut { set ::ut::failed 0 set ::ut::passed 0 proc ::ut::test {pars expected_results} { set r [::L3nisp_fm_hlib::planning_id {*}$pars] set m [format "\{$pars\}: 0x%08X = 0x%08X | %10i = %10i" $r $expected_results $r $expected_results] if {$r == $expected_results} { ::L2UTIL::print [concat $m " PASSED"] OK incr ::ut::passed } else { ::L2UTIL::print [concat $m " FAILED"] ERROR incr ::ut::failed } } proc ::ut::check_test_id {pars expected_test_id} { set r [::L3nisp_fm_hlib::planning_id {*}$pars] set test_id [expr ($r & 0xFFC00000) >> 22] set m [format "\{$pars\}: 0x%08X -> %10i = %10i" $r $test_id $expected_test_id] if {$test_id == $expected_test_id} { ::L2UTIL::print [concat $m " PASSED"] OK incr ::ut::passed } else { ::L2UTIL::print [concat $m " FAILED"] ERROR incr ::ut::failed } } ::L2TSEQ::begin $argv0 [concat $argv {-activity WE_Tests -conductor NISP_EGSE_Team }] ;# -mode SIMULATED namespace import ::L3nisp_fm_hlib::* ::L2UTIL::print "RUN TEST 1 (NOMINAL)\n" OK ::L2UTIL::print "temp type u_id led flux cycle dith | planning id (expected) | planning id (expected) | test-result" OK ::L2UTIL::print "-------------------------------------------------------------------------------------------------------" OK set is_cold [expr 1 << 23] set is_sft [expr 1 << 22] set is_fft [expr (1 << 22) + (1 << 31)] set type_b 24 set led_b 19 set cycle_b 4 set flux_b 16 ::ut::test {WARM EXPO 0 NONE 0 0 0} 0 ::ut::test {COLD EXPO 0 NONE 0 0 0} $is_cold ::ut::test {WARM SFT 0 NONE 0 0 0} $is_sft ::ut::test {WARM FFT 0 NONE 0 0 0} $is_fft ::ut::test {WARM EXPO 1 NONE 0 0 0} [expr 1 << $type_b] ::ut::test {WARM EXPO 255 NONE 0 0 0} [expr 255 << $type_b] ::ut::test {WARM SFT 1 NONE 0 0 0} [expr ( 1 << $type_b) + $is_sft] ::ut::test {WARM SFT 127 NONE 0 0 0} [expr (127 << $type_b) + $is_sft] ::ut::test {WARM FFT 1 NONE 0 0 0} [expr ( 1 << $type_b) + $is_fft] ::ut::test {WARM FFT 127 NONE 0 0 0} [expr (127 << $type_b) + $is_fft] ::ut::test {WARM EXPO 0 LED#1 0 0 0} [expr 1 << $led_b] ::ut::test {WARM EXPO 0 LED#2 0 0 0} [expr 2 << $led_b] ::ut::test {WARM EXPO 0 LED#3 0 0 0} [expr 3 << $led_b] ::ut::test {WARM EXPO 0 LED#4 0 0 0} [expr 4 << $led_b] ::ut::test {WARM EXPO 0 LED#5 0 0 0} [expr 5 << $led_b] ::ut::test {WARM EXPO 0 LED#1 7 0 0} [expr (1 << $led_b) + (7 << 16)] ::ut::test {WARM EXPO 0 NONE 0 4095 0} [expr (4095 << $cycle_b)] ::ut::test {WARM EXPO 0 NONE 0 0 15} 15 ::ut::test {WARM EXPO 255 LED#1 7 4095 15} [expr (255 << $type_b) + (1 << $led_b) + (7 << $flux_b) + (4095 << $cycle_b) + 15] ::ut::test {WARM EXPO 100 LED#2 5 1000 1} [expr (100 << $type_b) + (2 << $led_b) + (5 << $flux_b) + (1000 << $cycle_b) + 1] ::ut::test {COLD FFT 3 LED#2 5 1000 1} [expr $is_cold + $is_fft + (3 << $type_b) + (2 << $led_b) + (5 << $flux_b) + (1000 << $cycle_b) + 1] ::ut::test {COLD FFT 127 LED#5 7 4095 15} [expr $is_cold + $is_fft + (127 << $type_b) + (5 << $led_b) + (7 << $flux_b) + (4095 << $cycle_b) + 15] ::ut::test {WARM EXPO 255 NONE 0 0 1} [expr (255 << $type_b) + 1] set error_value 0xFFFFFFFF ::L2UTIL::print "\nRUN TEST 2 (OUT OF RANGE)\n" OK ::L2UTIL::print "temp type u_id led flux cycle dith | planning id (expected) | planning id (expected) | test-result" OK ::L2UTIL::print "-------------------------------------------------------------------------------------------------------" OK ::ut::test {WARM EXPO -1 NONE 0 0 0} $error_value ::ut::test {WARM EXPO 256 NONE 0 0 0} $error_value ::ut::test {WARM SFT -1 NONE 0 0 0} $error_value ::ut::test {WARM SFT 128 NONE 0 0 0} $error_value ::ut::test {WARM FFT -1 NONE 0 0 0} $error_value ::ut::test {WARM FFT 128 NONE 0 0 0} $error_value ::ut::test {WARM EXPO 0 NONE -1 0 0} $error_value ::ut::test {WARM EXPO 0 NONE 8 0 0} $error_value ::ut::test {WARM EXPO 0 NONE 0 -1 0} $error_value ::ut::test {WARM EXPO 0 NONE 0 4096 0} $error_value ::ut::test {WARM EXPO 0 NONE 0 0 -1} $error_value ::ut::test {WARM EXPO 0 NONE 0 0 16} $error_value ::L2UTIL::print "\nRUN TEST 3 (INVALID)\n" OK ::L2UTIL::print "temp type u_id led flux cycle dith | planning id (expected) | planning id (expected) | test-result" OK ::L2UTIL::print "-------------------------------------------------------------------------------------------------------" OK ::ut::test {DUM EXPO 0 NONE 0 0 0} $error_value ::ut::test {WARM DUM 0 NONE 0 0 0} $error_value ::ut::test {WARM EXPO DUM NONE 0 0 0} $error_value ::ut::test {WARM EXPO 0 DUM 0 0 0} $error_value ::ut::test {WARM EXPO 0 NONE DUM 0 0} $error_value ::ut::test {WARM EXPO 0 NONE 0 DUM 0} $error_value ::ut::test {WARM EXPO 0 NONE 0 0 DUM} $error_value ::ut::test {DUM DUM DUM DUM DUM DUM DUM} $error_value ::L2UTIL::print "\nRUN TEST 4 (TEST_ID)\n" OK ::L2UTIL::print "temp type u_id led flux cycle dith | planning id | tv2 test id (expected) | test-result" OK ::L2UTIL::print "-------------------------------------------------------------------------------------------------------" OK ::ut::check_test_id {WARM EXPO 255 NONE 0 0 0} 1020 if { $::ut::failed > 0 } { set msg_type ERROR } else { set msg_type OK } ::L2UTIL::print "\n\nRESULT: $::ut::passed passed, $::ut::failed FAILED\n" $msg_type ::L2TSEQ::end REQUEST }
run
|
edit
|
history
|
help
0
2
Trying bin mul floating point
NISP - Planning ID/Test ID
NISP - Wheel Movements 0.1
eerewr
1
Working for neg
Practice TCL
procedures.tcl
NISP - Planning ID Unit Test