diff options
author | Stewart Smith <stewart@linux.vnet.ibm.com> | 2014-12-19 16:40:25 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2014-12-19 16:40:25 +1100 |
commit | 6e99b04aef146654fb4c6577d2382ccd643b2b71 (patch) | |
tree | d55a967b8cc7d365270047b20e2b5f3281fc3c10 | |
parent | 9ceb72e4072e7c24e2c0abc0ba429da190b57fb8 (diff) | |
download | skiboot-6e99b04aef146654fb4c6577d2382ccd643b2b71.zip skiboot-6e99b04aef146654fb4c6577d2382ccd643b2b71.tar.gz skiboot-6e99b04aef146654fb4c6577d2382ccd643b2b71.tar.bz2 |
Add console-log unit test
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r-- | core/test/Makefile.check | 19 | ||||
-rw-r--r-- | core/test/run-console-log.c | 68 |
2 files changed, 87 insertions, 0 deletions
diff --git a/core/test/Makefile.check b/core/test/Makefile.check index 82c0b04..dece0ee 100644 --- a/core/test/Makefile.check +++ b/core/test/Makefile.check @@ -1,18 +1,31 @@ # -*-Makefile-*- CORE_TEST := core/test/run-device core/test/run-mem_region core/test/run-malloc core/test/run-malloc-speed core/test/run-mem_region_init core/test/run-mem_region_release_unused core/test/run-mem_region_release_unused_noalloc core/test/run-trace core/test/run-msg core/test/run-pel core/test/run-pool core/test/run-timer +CORE_TEST_NOSTUB := core/test/run-console-log + LCOV_EXCLUDE += $(CORE_TEST:%=%.c) core/test/stubs.c +LCOV_EXCLUDE += $(CORE_TEST_NOSTUB:%=%.c) /usr/include/* check: $(CORE_TEST:%=%-check) $(CORE_TEST:%=%-gcov-run) +check: $(CORE_TEST_NOSTUB:%=%-check) $(CORE_TEST_NOSTUB:%=%-gcov-run) + coverage: $(CORE_TEST:%=%-gcov-run) +coverage: $(CORE_TEST_NOSTUB:%=%-gcov-run) + $(CORE_TEST:%=%-gcov-run) : %-run: % $(call Q, TEST-COVERAGE ,$< , $<) +$(CORE_TEST_NOSTUB:%=%-gcov-run) : %-run: % + $(call Q, TEST-COVERAGE ,$< , $<) + $(CORE_TEST:%=%-check) : %-check: % $(call Q, RUN-TEST ,$(VALGRIND) $<, $<) +$(CORE_TEST_NOSTUB:%=%-check) : %-check: % + $(call Q, RUN-TEST ,$(VALGRIND) $<, $<) + core/test/stubs.o: core/test/stubs.c $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAGS) -g -c -o $@ $<, $<) @@ -21,9 +34,15 @@ $(CORE_TEST) : core/test/stubs.o $(CORE_TEST) : % : %.c $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAGS) -O0 -g -I include -I . -I libfdt -o $@ $< core/test/stubs.o, $<) +$(CORE_TEST_NOSTUB) : % : %.c + $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAGS) -O0 -g -I include -I . -I libfdt -o $@ $< , $<) + $(CORE_TEST:%=%-gcov): %-gcov : %.c % $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAGS) -fprofile-arcs -ftest-coverage -O0 -g -I include -I . -I libfdt -lgcov -o $@ $< core/test/stubs.o, $<) +$(CORE_TEST_NOSTUB:%=%-gcov) : %-gcov : %.c % + $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAGS) -fprofile-arcs -ftest-coverage -O0 -g -I include -I . -I libfdt -lgcov -o $@ $< , $<) + -include $(wildcard core/test/*.d) clean: core-test-clean diff --git a/core/test/run-console-log.c b/core/test/run-console-log.c new file mode 100644 index 0000000..2603247 --- /dev/null +++ b/core/test/run-console-log.c @@ -0,0 +1,68 @@ +/* Copyright 2013-2014 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <config.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <stdarg.h> + +#define __TEST__ + +static inline unsigned long mftb(void) +{ + return 42; +} + +#include "../console-log.c" + +struct debug_descriptor debug_descriptor; + +bool flushed_to_drivers; +char console_buffer[4096]; + +ssize_t console_write(bool flush_to_drivers, const void *buf, size_t count) +{ + flushed_to_drivers = flush_to_drivers; + memcpy(console_buffer, buf, count); + return count; +} + +int main(void) +{ + debug_descriptor.console_log_levels = 0x75; + + prlog(PR_EMERG, "Hello World"); + assert(memcmp(console_buffer, "[42,0] Hello World", strlen("[42,0] Hello World")) == 0); + assert(flushed_to_drivers==true); + + memset(console_buffer, 0, sizeof(console_buffer)); + + // Below log level + prlog(PR_TRACE, "Hello World"); + assert(console_buffer[0] == 0); + + // Should not be flushed to console + prlog(PR_DEBUG, "Hello World"); + assert(memcmp(console_buffer, "[42,7] Hello World", strlen("[42,7] Hello World")) == 0); + assert(flushed_to_drivers==false); + + printf("Hello World"); + assert(memcmp(console_buffer, "[42,5] Hello World", strlen("[42,5] Hello World")) == 0); + assert(flushed_to_drivers==true); + + return 0; +} |