E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 1 | // : vim ts=4 sw=4 noet : |
| 2 | /* |
| 3 | ================================================================================== |
| 4 | Copyright (c) 2019-2020 Nokia |
| 5 | Copyright (c) 2018-2020 AT&T Intellectual Property. |
| 6 | |
| 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | you may not use this file except in compliance with the License. |
| 9 | You may obtain a copy of the License at |
| 10 | |
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | |
| 13 | Unless required by applicable law or agreed to in writing, software |
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | See the License for the specific language governing permissions and |
| 17 | limitations under the License. |
| 18 | ================================================================================== |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | /* |
E. Scott Daniels | cc314e0 | 2020-09-15 10:27:34 -0400 | [diff] [blame] | 23 | Mnemonic: logging_test.c |
| 24 | Abstract: This test drives logging related tests. |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 25 | Date: 1 April 2019 |
| 26 | Author: E. Scott Daniels |
| 27 | */ |
| 28 | |
| 29 | #define NO_DUMMY_RMR 1 // no dummy rmr functions; we don't pull in rmr.h or agnostic.h |
E. Scott Daniels | fc5c77b | 2020-02-21 13:24:29 -0500 | [diff] [blame] | 30 | #define NO_EMULATION |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 31 | |
| 32 | #include "rmr_logging.h" |
| 33 | #include "logging.c" |
| 34 | #include "test_support.c" |
| 35 | |
| 36 | /* |
| 37 | Logging can be difficult to verify as stderr needs to be captured and examined. |
| 38 | We will verify internally what we can, and drive logging functions for coverage. |
| 39 | */ |
| 40 | int main( ) { |
| 41 | int llevel = 99; |
| 42 | int errors = 0; |
| 43 | |
| 44 | setenv( "RMR_HR_LOG", "1", 1 ); // drive for coverage in init |
| 45 | setenv( "RMR_LOG_VLEVEL", "90", 1 ); // force test for out of range during init |
| 46 | |
E. Scott Daniels | 77526eb | 2020-09-17 16:39:31 -0400 | [diff] [blame] | 47 | rmr_vlog( RMR_VL_CRIT, "crit message should be written\n" ); // force coverage; should drive init |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 48 | |
| 49 | llevel = rmr_vlog_init( ); |
| 50 | errors += fail_if_equal( llevel, 99, "llevel was not reset by vlog init" ); |
| 51 | errors += fail_if_equal( llevel, 90, "vlog init did not catch out of range vlog" ); |
| 52 | |
| 53 | llevel = 99; |
| 54 | setenv( "RMR_LOG_VLEVEL", "-10", 1 ); // force test for out of range during init |
| 55 | llevel = rmr_vlog_init( ); |
| 56 | errors += fail_if_equal( llevel, 99, "neg llevel was not reset by vlog init" ); |
| 57 | errors += fail_if_equal( llevel, -10, "vlog init did not catch out of range (neg) vlog" ); |
| 58 | |
| 59 | rmr_set_vlevel( 2 ); |
E. Scott Daniels | 77526eb | 2020-09-17 16:39:31 -0400 | [diff] [blame] | 60 | |
| 61 | /* |
| 62 | The remainder of these tests can be validated only by looking at the stderr |
| 63 | for the process. If any "should not be written" messages appear, then the |
| 64 | test should be marked as a failure. In a similar vein, the number of |
| 65 | expected "should be written" messages should be found. |
| 66 | */ |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 67 | rmr_vlog( RMR_VL_DEBUG, "debug message should not be written\n" ); |
| 68 | rmr_vlog( RMR_VL_INFO, "info message should not be written\n" ); |
| 69 | rmr_vlog( RMR_VL_WARN, "warn message should not be written\n" ); |
| 70 | rmr_vlog( RMR_VL_ERR, "error message should be written\n" ); |
| 71 | rmr_vlog( RMR_VL_CRIT, "crit message should be written\n" ); |
E. Scott Daniels | 77526eb | 2020-09-17 16:39:31 -0400 | [diff] [blame] | 72 | |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 73 | rmr_set_vlevel( 5 ); |
| 74 | rmr_vlog( RMR_VL_DEBUG, "debug message should be written\n" ); |
| 75 | rmr_vlog( RMR_VL_INFO, "info message should be written\n" ); |
| 76 | rmr_vlog( RMR_VL_WARN, "warn message should be written\n" ); |
| 77 | rmr_vlog( RMR_VL_ERR, "error message should be written\n" ); |
| 78 | rmr_vlog( RMR_VL_CRIT, "crit message should be written\n" ); |
E. Scott Daniels | 77526eb | 2020-09-17 16:39:31 -0400 | [diff] [blame] | 79 | |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 80 | rmr_set_vlevel( 0 ); |
| 81 | rmr_vlog( RMR_VL_DEBUG, "debug message should not be written\n" ); |
| 82 | rmr_vlog( RMR_VL_INFO, "info message should not be written\n" ); |
| 83 | rmr_vlog( RMR_VL_WARN, "warn message should not be written\n" ); |
| 84 | rmr_vlog( RMR_VL_ERR, "error message should not be written\n" ); |
| 85 | rmr_vlog( RMR_VL_CRIT, "crit message should not be written\n" ); |
| 86 | |
| 87 | rmr_set_vlevel( 1 ); |
| 88 | rmr_vlog_force( RMR_VL_DEBUG, "debug forced message should be written\n" ); |
| 89 | rmr_vlog_force( RMR_VL_INFO, "info forced message should be written\n" ); |
| 90 | rmr_vlog_force( RMR_VL_WARN, "warn forced message should be written\n" ); |
| 91 | rmr_vlog_force( RMR_VL_ERR, "error forced message should be written\n" ); |
| 92 | rmr_vlog_force( RMR_VL_CRIT, "crit forced message should be written\n" ); |
| 93 | |
E. Scott Daniels | 77526eb | 2020-09-17 16:39:31 -0400 | [diff] [blame] | 94 | // CAUTION -- this needs to be manually updated when 'should be' messages are added!! |
| 95 | fprintf( stderr, "<INFO> expeted 'should be' messages count is 13\n" ); |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 96 | |
| 97 | rmr_vlog( -1, "out of range message might be written\n" ); // drive range checks |
| 98 | rmr_vlog( 10, "out of range message should not be written\n" ); |
| 99 | |
E. Scott Daniels | 77526eb | 2020-09-17 16:39:31 -0400 | [diff] [blame] | 100 | rmr_vlog_force( -1, "out of range message might be written\n" ); // drive range checks |
| 101 | rmr_vlog_force( 10, "out of range message should be written (as debug)\n" ); // force with high log level should set to debug |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 102 | |
E. Scott Daniels | 77526eb | 2020-09-17 16:39:31 -0400 | [diff] [blame] | 103 | test_summary( errors, "logging tests" ); |
E. Scott Daniels | 0d4def6 | 2020-01-28 16:50:27 -0500 | [diff] [blame] | 104 | return errors > 0; |
| 105 | } |