From 802e62cbbdb8fc740e9195c24c7a67a4a956592e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Sun, 13 Sep 2020 16:55:22 +0200 Subject: [PATCH] Now logging defaults to stderr. --- README.md | 3 +- src/cmdline.cc | 9 ++++- src/config.h | 2 +- src/main.cc | 70 +++++++++++++++++++++++++++-------- src/serial.cc | 3 +- src/wmbus.cc | 34 +++++++++-------- src/wmbus.h | 9 ++++- tests/test_additional_json.sh | 6 +-- tests/test_aes.sh | 2 +- tests/test_apas.sh | 4 +- tests/test_c1_meters.sh | 2 +- tests/test_config1.sh | 2 +- tests/test_config4.sh | 2 +- tests/test_linkmodes.sh | 4 +- tests/test_listen_to_all.sh | 2 +- tests/test_meterfiles.sh | 10 ++--- tests/test_oneshot.sh | 4 +- tests/test_shell.sh | 2 +- tests/test_shell2.sh | 2 +- tests/test_t1_meters.sh | 4 +- tests/test_unknown.sh | 2 +- tests/test_wrongkeys.sh | 12 ++++-- 22 files changed, 127 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index 12592cd..ee20de3 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,8 @@ As you can use: --separator= change field separator to c --shell= invokes cmdline with env variables containing the latest reading --useconfig= load config files from dir/etc - --usestderr write debug/verbose and logging output to stderr + --usestderr write notices/debug/verbose and other logging output to stderr (the default) + --usestdoutforlogging write debug/verbose and logging output to stdout --verbose for more information As you can use: diff --git a/src/cmdline.cc b/src/cmdline.cc index a985b47..213eda0 100644 --- a/src/cmdline.cc +++ b/src/cmdline.cc @@ -351,8 +351,13 @@ unique_ptr parseCommandLine(int argc, char **argv) { i++; continue; } - if (!strncmp(argv[i], "--usestderr=", 10)) { - c->use_stderr = true; + if (!strncmp(argv[i], "--usestderr", 11)) { + c->use_stderr_for_log = true; + i++; + continue; + } + if (!strncmp(argv[i], "--usestdoutforlogging", 13)) { + c->use_stderr_for_log = false; i++; continue; } diff --git a/src/config.h b/src/config.h index 18740a2..311500c 100644 --- a/src/config.h +++ b/src/config.h @@ -65,7 +65,7 @@ struct Configuration MeterFileNaming meterfiles_naming {}; MeterFileTimestamp meterfiles_timestamp {}; // Default is never. bool use_logfile {}; - bool use_stderr {}; + bool use_stderr_for_log = true; // Default is to use stderr for logging. std::string logfile; bool json {}; bool fields {}; diff --git a/src/main.cc b/src/main.cc index 2868111..e8b879f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -77,6 +77,10 @@ set not_serial_wmbus_devices_; // but they might not be available for wmbusmeters. set not_swradio_wmbus_devices_; +// When manually supplying stdin or a file, then, after +// it has been read, do not open it again! +set do_not_open_file_again_; + // Rendering the telegrams to json,fields or shell calls is // done by the printer. unique_ptr printer_; @@ -338,7 +342,8 @@ void list_shell_envs(Configuration *config, string meter_type) &config->jsons, &config->selected_fields); - for (auto &e : envs) { + for (auto &e : envs) + { int p = e.find('='); string key = e.substr(0,p); printf("%s\n", key.c_str()); @@ -498,6 +503,10 @@ void check_for_dead_wmbus_devices(Configuration *config) if (!w->isWorking()) { not_working.push_back(w.get()); + if (!config->use_auto_detect) + { + notice("Lost %s closing %s\n", w->device().c_str(), toString(w->type())); + } } } @@ -535,8 +544,14 @@ void check_for_dead_wmbus_devices(Configuration *config) void open_wmbus_device(Configuration *config, string how, string device, Detected *detected) { // A newly plugged in device has been manually configured or automatically detected! Start using it! - info("(main) %s %s on %s\n", how.c_str(), toString(detected->type), device.c_str()); - + if (config->use_auto_detect) + { + notice("Detected %s %s on %s\n", how.c_str(), toString(detected->type), device.c_str()); + } + else + { + verbose("(main) %s %s on %s\n", how.c_str(), toString(detected->type), device.c_str()); + } LOCK("(main)", "perform_auto_scan_of_devices", devices_lock_); unique_ptr w = createWMBusDeviceFrom(detected, config, serial_manager_.get()); wmbus_devices_.push_back(std::move(w)); @@ -571,7 +586,7 @@ void perform_auto_scan_of_serial_devices(Configuration *config) { debug("(main) device %s not currently used, detect contents...\n", device.c_str()); // This serial device is not in use. - Detected detected = detectImstAmberCul(device, "", "", serial_manager_.get()); + Detected detected = detectImstAmberCul(device, "", "", serial_manager_.get(), true, false, false); if (detected.type == DEVICE_UNKNOWN) { // This serial device was something that we could not recognize. @@ -645,14 +660,26 @@ void detectAndConfigureWMBusDevices(Configuration *config) continue; } - Detected detected = detectWMBusDeviceSetting(device.file, - device.suffix, - device.linkmodes, - serial_manager_.get()); - - if (detected.type != DEVICE_UNKNOWN) + if (do_not_open_file_again_.count(device.file) == 0) { - open_wmbus_device(config, "manual configuration", device.str(), &detected); + Detected detected = detectWMBusDeviceSetting(device.file, + device.suffix, + device.linkmodes, + serial_manager_.get()); + + if (detected.type != DEVICE_UNKNOWN) + { + if (detected.is_stdin || detected.is_file) + { + // Only read stdin and files once! + do_not_open_file_again_.insert(device.file); + } + open_wmbus_device(config, "manual configuration", device.str(), &detected); + } + } + else + { + trace("(MAIN) ignoring handled file %s\n", device.file.c_str()); } } @@ -708,7 +735,7 @@ bool start(Configuration *config) debugEnabled(config->debug); internalTestingEnabled(config->internaltesting); traceEnabled(config->trace); - stderrEnabled(config->use_stderr); + stderrEnabled(config->use_stderr_for_log); setAlarmShells(config->alarm_shells); logStartInformation(config); @@ -749,16 +776,29 @@ bool start(Configuration *config) printed_warning_ = true; detectAndConfigureWMBusDevices(config); - if (wmbus_devices_.size() == 0) + if (!config->use_auto_detect) { - info("(main) no wmbus device detected, waiting for a device to be plugged in.\n"); + serial_manager_->expectDevicesToWork(); + if (wmbus_devices_.size() == 0) + { + notice("(main) no wmbus device configured! Exiting.\n"); + serial_manager_->stop(); + } + } + else + { + if (wmbus_devices_.size() == 0) + { + notice("(main) no wmbus device detected, waiting for a device to be plugged in.\n"); + } } // Every 2 seconds detect any plugged in or removed wmbus devices. serial_manager_->startRegularCallback("HOT_PLUG_DETECTOR", 2, [&](){ - detectAndConfigureWMBusDevices(config); + if (serial_manager_ && config) + detectAndConfigureWMBusDevices(config); }); if (config->daemon) diff --git a/src/serial.cc b/src/serial.cc index ffbf95a..9ece822 100644 --- a/src/serial.cc +++ b/src/serial.cc @@ -596,7 +596,7 @@ void SerialDeviceFile::close() ::close(fd_); fd_ = -1; manager_->closed(this); - verbose("(serialtty) closed %s %d\n", file_.c_str(), fd_); + verbose("(serialfile) closed %s %d\n", file_.c_str(), fd_); } void SerialDeviceFile::checkIfShouldReopen() @@ -895,6 +895,7 @@ void *SerialCommunicationManagerImp::eventLoop() { if (!d->skippingCallbacks()) { + trace("(SERIAL) select read on fd %d\n", d->fd()); FD_SET(d->fd(), &readfds); } if (!d->working()) all_working = false; diff --git a/src/wmbus.cc b/src/wmbus.cc index fd03546..603be2c 100644 --- a/src/wmbus.cc +++ b/src/wmbus.cc @@ -473,7 +473,10 @@ string mediaTypeJSON(int a_field_device_type) Detected detectImstAmberCul(string file, string suffix, string linkmodes, - SerialCommunicationManager *handler) + SerialCommunicationManager *handler, + bool is_tty, + bool is_stdin, + bool is_file) { Detected detected {}; detected.device = { file, suffix, "" }; @@ -505,7 +508,7 @@ Detected detectImstAmberCul(string file, } // We could not auto-detect either. - return { { file, suffix }, DEVICE_UNKNOWN, 0, false }; + return { { file, suffix }, DEVICE_UNKNOWN, 0, false, is_tty, is_stdin, is_file }; } /** @@ -564,6 +567,7 @@ Detected detectWMBusDeviceSetting(string file, bool is_file = checkFileExists(file.c_str()); debug("(detect) is_tty=%d is_stdin=%d is_file=%d\n", is_tty, is_stdin, is_file); + if (!is_tty && !is_stdin && !is_file) { debug("(detect) not a valid device file %s\n", file.c_str()); @@ -573,21 +577,21 @@ Detected detectWMBusDeviceSetting(string file, bool override_tty = !is_tty; - if (suffix == "amb8465") return { { file, suffix }, DEVICE_AMB8465, 0, override_tty }; - if (suffix == "im871a") return { { file, suffix }, DEVICE_IM871A, 0, override_tty }; - if (suffix == "rfmrx2") return { { file, suffix }, DEVICE_RFMRX2, 0, override_tty }; - if (suffix == "rtlwmbus") return { { file, suffix }, DEVICE_RTLWMBUS, 0, override_tty }; - if (suffix == "rtl433") return { { file, suffix}, DEVICE_RTL433, 0, override_tty }; - if (suffix == "cul") return { { file, suffix}, DEVICE_CUL, 0, override_tty }; - if (suffix == "d1tc") return { { file, suffix}, DEVICE_D1TC, 0, override_tty }; - if (suffix == "wmb13u") return { { file, suffix}, DEVICE_WMB13U, 0, override_tty }; - if (suffix == "simulation") return { { file, suffix}, DEVICE_SIMULATOR, 0, override_tty }; + if (suffix == "amb8465") return { { file, suffix }, DEVICE_AMB8465, 0, override_tty, is_tty, is_stdin, is_file }; + if (suffix == "im871a") return { { file, suffix }, DEVICE_IM871A, 0, override_tty, is_tty, is_stdin, is_file }; + if (suffix == "rfmrx2") return { { file, suffix }, DEVICE_RFMRX2, 0, override_tty, is_tty, is_stdin, is_file }; + if (suffix == "rtlwmbus") return { { file, suffix }, DEVICE_RTLWMBUS, 0, override_tty, is_tty, is_stdin, is_file }; + if (suffix == "rtl433") return { { file, suffix}, DEVICE_RTL433, 0, override_tty, is_tty, is_stdin, is_file }; + if (suffix == "cul") return { { file, suffix}, DEVICE_CUL, 0, override_tty, is_tty, is_stdin, is_file }; + if (suffix == "d1tc") return { { file, suffix}, DEVICE_D1TC, 0, override_tty, is_tty, is_stdin, is_file }; + if (suffix == "wmb13u") return { { file, suffix}, DEVICE_WMB13U, 0, override_tty, is_tty, is_stdin, is_file }; + if (suffix == "simulation") return { { file, suffix}, DEVICE_SIMULATOR, 0, override_tty, is_tty, is_stdin, is_file }; // If the suffix is a number, then assume that it is a baud rate. - if (isNumber(suffix)) return { { file, suffix} , DEVICE_RAWTTY, atoi(suffix.c_str()), override_tty }; + if (isNumber(suffix)) return { { file, suffix} , DEVICE_RAWTTY, atoi(suffix.c_str()), override_tty, is_tty, is_stdin, is_file }; // If the suffix is empty and its not a tty, then read raw telegrams from stdin or the file. - if (suffix == "" && !is_tty) return { { file, suffix}, DEVICE_RAWTTY, 0, true }; + if (suffix == "" && !is_tty) return { { file, suffix}, DEVICE_RAWTTY, 0, true, is_tty, is_stdin, is_file }; if (suffix != "") { @@ -597,7 +601,7 @@ Detected detectWMBusDeviceSetting(string file, // Ok, we are left with a single /dev/ttyUSB0 lets talk to it // to figure out what is connected to it. We currently only // know how to detect Imst, Amber or CUL dongles. - return detectImstAmberCul(file, suffix, linkmodes, handler); + return detectImstAmberCul(file, suffix, linkmodes, handler, is_tty, is_stdin, is_file); } /* @@ -3378,7 +3382,7 @@ void WMBusCommonImplementation::disconnectedFromDevice() { if (is_working_) { - info("(wmbus) lost %s closing %s\n", device().c_str(), toString(type())); + debug("(wmbus) disconnect %s closing %s\n", device().c_str(), toString(type())); is_working_ = false; } } diff --git a/src/wmbus.h b/src/wmbus.h index d2b485f..f748c12 100644 --- a/src/wmbus.h +++ b/src/wmbus.h @@ -97,12 +97,16 @@ struct Detected // instead open the device->file as a file instead . This is to allows feeding the wmbus drivers // using stdin or a file. This is primarily used for internal testing. bool override_tty; + bool is_tty; + bool is_file; + bool is_stdin; void set(WMBusDeviceType t, int br, bool ot) { type = t; baudrate = br; override_tty = ot; + is_tty = is_file = is_stdin = false; } }; @@ -581,6 +585,9 @@ AccessCheck factoryResetAMB8465(string device, SerialCommunicationManager *handl Detected detectImstAmberCul(string file, string suffix, string linkmodes, - SerialCommunicationManager *handler); + SerialCommunicationManager *handler, + bool is_tty, + bool is_stdin, + bool is_file); #endif diff --git a/tests/test_additional_json.sh b/tests/test_additional_json.sh index 6ea42a0..78051ba 100755 --- a/tests/test_additional_json.sh +++ b/tests/test_additional_json.sh @@ -10,7 +10,7 @@ TESTRESULT="ERROR" cat simulations/simulation_additional_json.txt | grep '^{' > $TEST/test_expected.txt $PROG --format=json --json_floor=5 --json_address="RoodRd 42" simulations/simulation_additional_json.txt \ MyTapWater multical21 76348799 "" \ - > $TEST/test_output.txt + > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then @@ -29,7 +29,7 @@ if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi TESTNAME="Test additional shell envs from cmdline" TESTRESULT="ERROR" -$PROG --json_floor=5 --json_house="alfa beta" --listenvs=multical21 > $TEST/test_output.txt +$PROG --json_floor=5 --json_house="alfa beta" --listenvs=multical21 > $TEST/test_output.txt 2> $TEST/test_stderr.txt ENVS=$(cat $TEST/test_output.txt | tr '\n' ' ') @@ -65,7 +65,7 @@ if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi TESTNAME="Test additional json from wmbusmeters.conf and from meter file" TESTRESULT="ERROR" -$PROG --useconfig=tests/config6 --device=simulations/simulation_shell.txt --listento=t1 > $TEST/test_output.txt +$PROG --useconfig=tests/config6 --device=simulations/simulation_shell.txt --listento=t1 > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then diff --git a/tests/test_aes.sh b/tests/test_aes.sh index 22cc0d2..2fa3704 100755 --- a/tests/test_aes.sh +++ b/tests/test_aes.sh @@ -16,7 +16,7 @@ cat $TEST/test_input.txt | $PROG --format=json "stdin:rtlwmbus" \ ApWater apator162 88888888 00000000000000000000000000000000 \ Vatten multical21 76348799 28F64A24988064A079AA2C807D6102AE \ Wasser supercom587 77777777 5065747220486F6C79737A6577736B69 \ - > $TEST/test_output.txt + > $TEST/test_output.txt 2> $TEST/test_stderr.txt cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt diff $TEST/test_expected.txt $TEST/test_response.txt diff --git a/tests/test_apas.sh b/tests/test_apas.sh index 0c6a2b3..e972482 100755 --- a/tests/test_apas.sh +++ b/tests/test_apas.sh @@ -18,7 +18,7 @@ METERS="Wasser apator162 20202020 NOKEY MyTapWatere apator162 27202020 NOKEY" cat simulations/simulation_apas.txt | grep '^{' > $TEST/test_expected.txt -$PROG --format=json simulations/simulation_apas.txt $METERS > $TEST/test_output.txt +$PROG --format=json simulations/simulation_apas.txt $METERS > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt @@ -31,7 +31,7 @@ then fi cat simulations/simulation_apas.txt | grep '^|' | sed 's/^|//' > $TEST/test_expected.txt -$PROG --format=fields simulations/simulation_apas.txt $METERS > $TEST/test_output.txt +$PROG --format=fields simulations/simulation_apas.txt $METERS > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then cat $TEST/test_output.txt | sed 's/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9].[0-9][0-9]$/1111-11-11 11:11.11/' > $TEST/test_responses.txt diff --git a/tests/test_c1_meters.sh b/tests/test_c1_meters.sh index 1046d7a..c8ff30a 100755 --- a/tests/test_c1_meters.sh +++ b/tests/test_c1_meters.sh @@ -17,7 +17,7 @@ $PROG --format=json simulations/simulation_c1.txt \ MyElement qcaloric 78563412 "" \ Rum cma12w 66666666 "" \ My403Cooling multical403 78780102 "" \ - > $TEST/test_output.txt + > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then diff --git a/tests/test_config1.sh b/tests/test_config1.sh index 44956ed..93f9e10 100755 --- a/tests/test_config1.sh +++ b/tests/test_config1.sh @@ -9,7 +9,7 @@ TESTRESULT="ERROR" cat simulations/simulation_c1.txt | grep '^{' > $TEST/test_expected.txt -$PROG --useconfig=tests/config1 > $TEST/test_output.txt +$PROG --useconfig=tests/config1 > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then diff --git a/tests/test_config4.sh b/tests/test_config4.sh index 43ffb6a..1afc1b2 100755 --- a/tests/test_config4.sh +++ b/tests/test_config4.sh @@ -9,7 +9,7 @@ TESTRESULT="ERROR" cat simulations/simulation_conversionsadded.txt | grep '^{' > $TEST/test_expected.txt -$PROG --useconfig=tests/config4 > $TEST/test_output.txt +$PROG --useconfig=tests/config4 > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then diff --git a/tests/test_linkmodes.sh b/tests/test_linkmodes.sh index 6b051bd..8ac59c6 100755 --- a/tests/test_linkmodes.sh +++ b/tests/test_linkmodes.sh @@ -44,7 +44,7 @@ fi TESTNAME="Test that setting multical21 to t1 fails" TESTRESULT="ERROR" -MSG=$($PROG --listento=c1,t1 simulations/simulation_t1_and_c1.txt \ +MSG=$($PROG --listento=c1,t1 --usestdoutforlog simulations/simulation_t1_and_c1.txt \ MyTapWater multical21:t1 76348799 "" \ Wasser apator162:c1 20202020 "") @@ -60,7 +60,7 @@ fi TESTNAME="Test that the warning for missed telegrams work" TESTRESULT="ERROR" -MSG=$($PROG --s1 simulations/simulation_t1_and_c1.txt \ +MSG=$($PROG --s1 --usestdoutforlog simulations/simulation_t1_and_c1.txt \ MyTapWater multical21:c1 76348799 "" \ Wasser apator162:t1 20202020 "" | tr -d ' \n') diff --git a/tests/test_listen_to_all.sh b/tests/test_listen_to_all.sh index f681eb7..9354104 100755 --- a/tests/test_listen_to_all.sh +++ b/tests/test_listen_to_all.sh @@ -196,7 +196,7 @@ fi TESTNAME="Test listen and print any meter heard on stdout" TESTRESULT="ERROR" -$PROG --t1 simulations/simulation_t1.txt 2>&1 > $LOGFILE +$PROG --t1 simulations/simulation_t1.txt 2> $LOGFILE RES=$(diff $LOGFILE $LOGFILE_EXPECTED) diff --git a/tests/test_meterfiles.sh b/tests/test_meterfiles.sh index db99f6f..76fa249 100755 --- a/tests/test_meterfiles.sh +++ b/tests/test_meterfiles.sh @@ -10,7 +10,7 @@ TESTRESULT="ERROR" rm -f /tmp/MyTapWater cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt -$PROG --meterfiles --format=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" > /dev/null +$PROG --meterfiles --format=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" > /dev/null 2> $TEST/test_stderr.txt cat /tmp/MyTapWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt diff $TEST/test_expected.txt $TEST/test_response.txt if [ "$?" = "0" ] @@ -28,7 +28,7 @@ TESTRESULT="ERROR" rm -rf /tmp/testmeters mkdir /tmp/testmeters cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt -$PROG --meterfiles=/tmp/testmeters --meterfilesnaming=name-id --format=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" > /dev/null +$PROG --meterfiles=/tmp/testmeters --meterfilesnaming=name-id --format=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" > /dev/null 2> $TEST/test_stderr.txt cat /tmp/testmeters/MyTapWater-76348799 | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt diff $TEST/test_expected.txt $TEST/test_response.txt if [ "$?" = "0" ] @@ -46,7 +46,7 @@ TESTRESULT="ERROR" rm -rf /tmp/testmeters mkdir /tmp/testmeters cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt -$PROG --meterfiles=/tmp/testmeters --meterfilesnaming=id --format=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" +$PROG --meterfiles=/tmp/testmeters --meterfilesnaming=id --format=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" 2> $TEST/test_stderr.txt cat /tmp/testmeters/76348799 | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt diff $TEST/test_expected.txt $TEST/test_response.txt if [ "$?" = "0" ] @@ -65,7 +65,7 @@ TESTRESULT="ERROR" rm -rf /tmp/testmeters mkdir /tmp/testmeters cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt -$PROG --meterfiles=/tmp/testmeters --meterfilesnaming=id --meterfilestimestamp=day --format=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" +$PROG --meterfiles=/tmp/testmeters --meterfilesnaming=id --meterfilestimestamp=day --format=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" 2> $TEST/test_stderr.txt cat /tmp/testmeters/76348799_$(date +%Y-%m-%d) | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt diff $TEST/test_expected.txt $TEST/test_response.txt if [ "$?" = "0" ] @@ -80,7 +80,7 @@ if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi rm -rf /tmp/testmeters mkdir /tmp/testmeters cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt -$PROG --meterfiles=/tmp/testmeters --meterfilesnaming=id --meterfilestimestamp=minute --format=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" +$PROG --meterfiles=/tmp/testmeters --meterfilesnaming=id --meterfilestimestamp=minute --format=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" 2> $TEST/test_stderr.txt cat /tmp/testmeters/76348799_$(date +%Y-%m-%d_%H:%M) | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt diff $TEST/test_expected.txt $TEST/test_response.txt if [ "$?" = "0" ] diff --git a/tests/test_oneshot.sh b/tests/test_oneshot.sh index f0a28e1..bbc84b8 100755 --- a/tests/test_oneshot.sh +++ b/tests/test_oneshot.sh @@ -8,9 +8,9 @@ mkdir -p testoutput TEST=testoutput SIM=simulations/simulation_c1.txt -$PROG --oneshot --verbose $SIM MyHeater multical302 67676767 NOKEY MyTapWater multical21 76348799 NOKEY > $TEST/test_output.txt +$PROG --oneshot --verbose $SIM MyHeater multical302 67676767 NOKEY MyTapWater multical21 76348799 NOKEY > $TEST/test_output.txt 2> $TEST/test_stderr.txt -RES=$(cat $TEST/test_output.txt | grep -o "(main) all meters have received at least one update, stopping." | tail -n 1) +RES=$(cat $TEST/test_stderr.txt | grep -o "(main) all meters have received at least one update, stopping." | tail -n 1) if [ "$RES" = "(main) all meters have received at least one update, stopping." ] then diff --git a/tests/test_shell.sh b/tests/test_shell.sh index 6e0537c..3114585 100755 --- a/tests/test_shell.sh +++ b/tests/test_shell.sh @@ -8,7 +8,7 @@ TEST=testoutput TESTNAME="Test shell invocation" TESTRESULT="ERROR" -$PROG --shell='echo "$METER_JSON"' simulations/simulation_shell.txt MWW supercom587 12345678 "" > $TEST/test_output.txt +$PROG --shell='echo "$METER_JSON"' simulations/simulation_shell.txt MWW supercom587 12345678 "" > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt diff --git a/tests/test_shell2.sh b/tests/test_shell2.sh index 2aace32..43ccbfb 100755 --- a/tests/test_shell2.sh +++ b/tests/test_shell2.sh @@ -7,7 +7,7 @@ mkdir -p $TEST TESTNAME="Test shell in config file" TESTRESULT="ERROR" -$PROG --useconfig=tests/config5 > $TEST/test_output.txt +$PROG --useconfig=tests/config5 > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then diff --git a/tests/test_t1_meters.sh b/tests/test_t1_meters.sh index 7365b89..aa18a3b 100755 --- a/tests/test_t1_meters.sh +++ b/tests/test_t1_meters.sh @@ -36,7 +36,7 @@ METERS="MyWarmWater supercom587 12345678 NOKEY Witer topaseskr 78563412 NOKEY" cat simulations/simulation_t1.txt | grep '^{' > $TEST/test_expected.txt -$PROG --format=json simulations/simulation_t1.txt $METERS > $TEST/test_output.txt +$PROG --format=json simulations/simulation_t1.txt $METERS > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt @@ -51,7 +51,7 @@ then fi cat simulations/simulation_t1.txt | grep '^|' | sed 's/^|//' > $TEST/test_expected.txt -$PROG --format=fields simulations/simulation_t1.txt $METERS > $TEST/test_output.txt +$PROG --format=fields simulations/simulation_t1.txt $METERS > $TEST/test_output.txt 2> $TEST/test_stderr.txt if [ "$?" = "0" ] then cat $TEST/test_output.txt | sed 's/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9].[0-9][0-9]$/1111-11-11 11:11.11/' > $TEST/test_responses.txt diff --git a/tests/test_unknown.sh b/tests/test_unknown.sh index 7388dca..e482d82 100755 --- a/tests/test_unknown.sh +++ b/tests/test_unknown.sh @@ -21,7 +21,7 @@ cat > $TEST/test_expected.txt < $TEST/test_output.txt +$PROG --format=json --usestdoutforlogging simulations/simulation_unknown.txt $METERS > $TEST/test_output.txt if [ "$?" = "0" ] then cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt diff --git a/tests/test_wrongkeys.sh b/tests/test_wrongkeys.sh index 8eff2e7..b6e396e 100755 --- a/tests/test_wrongkeys.sh +++ b/tests/test_wrongkeys.sh @@ -16,9 +16,15 @@ cat $TEST/test_input.txt | $PROG --format=json "stdin:rtlwmbus" \ ApWater apator162 88888888 00000000000000000000000000000001 \ Vatten multical21 76348799 28F64A24988064A079AA2C807D6102AF \ Wasser supercom587 77777777 5065747220486F6C79737A6577736B6A \ - > $TEST/test_output.txt + > $TEST/test_output.txt 2> $TEST/test_stderr.txt -cat $TEST/test_output.txt | grep -v '{"media' > $TEST/test_response.txt +if [ -s $TEST/test_output.txt ] +then + echo "Bad no stdout expected! But got bytes anyway!" + echo "ERROR: $TESTNAME" + TESTRESULT="ERROR" + exit 1 +fi cat < $TEST/test_expected.txt (wmbus) decrypted content failed check, did you use the correct decryption key? Ignoring telegram. @@ -26,7 +32,7 @@ cat < $TEST/test_expected.txt (wmbus) decrypted content failed check, did you use the correct decryption key? Ignoring telegram. EOF -diff $TEST/test_expected.txt $TEST/test_response.txt +diff $TEST/test_expected.txt $TEST/test_stderr.txt if [ "$?" = "0" ] then echo "OK: $TESTNAME"