From c2c7840a42aaab8354bb1997d141149d30316603 Mon Sep 17 00:00:00 2001 From: Cary Coutant Date: Wed, 25 Jan 2012 07:34:55 +0000 Subject: * int_encoding.cc (read_unsigned_LEB_128): Replaced with inline definition and ... (read_unsigned_LEB_128_x): ... this new function. (read_signed_LEB_128): Replaced with inline definition and ... (read_signed_LEB_128_x): ... this new function. * int_encoding.h (read_unsigned_LEB_128_x): New function. (read_unsigned_LEB_128): Add inline definition. (read_signed_LEB_128_x): New function. (read_signed_LEB_128): Add inline definition. * testsuite/Makefile.am (leb128_unittest): New unit test. * testsuite/Makefile.in: Regenerate. * testsuite/leb128_unittest.cc: New unit test. --- gold/testsuite/Makefile.am | 3 ++ gold/testsuite/Makefile.in | 22 ++++++++-- gold/testsuite/leb128_unittest.cc | 88 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 gold/testsuite/leb128_unittest.cc (limited to 'gold/testsuite') diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 794dac8fc2..c7209f31a9 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -94,6 +94,9 @@ object_unittest_SOURCES = object_unittest.cc check_PROGRAMS += binary_unittest binary_unittest_SOURCES = binary_unittest.cc +check_PROGRAMS += leb128_unittest +leb128_unittest_SOURCES = leb128_unittest.cc + endif NATIVE_OR_CROSS_LINKER # --------------------------------------------------------------------- diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index af62c8d1dd..c5c1ae6cb3 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -54,7 +54,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ $(am__EXEEXT_34) $(am__EXEEXT_35) $(am__EXEEXT_36) \ $(am__EXEEXT_37) $(am__EXEEXT_38) @NATIVE_OR_CROSS_LINKER_TRUE@am__append_1 = object_unittest \ -@NATIVE_OR_CROSS_LINKER_TRUE@ binary_unittest +@NATIVE_OR_CROSS_LINKER_TRUE@ binary_unittest leb128_unittest # Test --detect-odr-violations @@ -646,7 +646,8 @@ am_libgoldtest_a_OBJECTS = test.$(OBJEXT) testmain.$(OBJEXT) \ testfile.$(OBJEXT) libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS) @NATIVE_OR_CROSS_LINKER_TRUE@am__EXEEXT_1 = object_unittest$(EXEEXT) \ -@NATIVE_OR_CROSS_LINKER_TRUE@ binary_unittest$(EXEEXT) +@NATIVE_OR_CROSS_LINKER_TRUE@ binary_unittest$(EXEEXT) \ +@NATIVE_OR_CROSS_LINKER_TRUE@ leb128_unittest$(EXEEXT) @GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_2 = icf_virtual_function_folding_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_pic_test$(EXEEXT) @@ -1221,6 +1222,13 @@ justsyms_exec_LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ large_OBJECTS = $(am_large_OBJECTS) large_LINK = $(CCLD) $(large_CFLAGS) $(CFLAGS) $(large_LDFLAGS) \ $(LDFLAGS) -o $@ +@NATIVE_OR_CROSS_LINKER_TRUE@am_leb128_unittest_OBJECTS = \ +@NATIVE_OR_CROSS_LINKER_TRUE@ leb128_unittest.$(OBJEXT) +leb128_unittest_OBJECTS = $(am_leb128_unittest_OBJECTS) +leb128_unittest_LDADD = $(LDADD) +leb128_unittest_DEPENDENCIES = libgoldtest.a ../libgold.a \ + ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) local_labels_test_SOURCES = local_labels_test.c local_labels_test_OBJECTS = local_labels_test.$(OBJEXT) local_labels_test_LDADD = $(LDADD) @@ -1701,7 +1709,8 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \ incremental_test_3.c incremental_test_4.c incremental_test_5.c \ incremental_test_6.c $(initpri1_SOURCES) $(initpri2_SOURCES) \ $(initpri3a_SOURCES) $(initpri3b_SOURCES) $(justsyms_SOURCES) \ - $(justsyms_exec_SOURCES) $(large_SOURCES) local_labels_test.c \ + $(justsyms_exec_SOURCES) $(large_SOURCES) \ + $(leb128_unittest_SOURCES) local_labels_test.c \ many_sections_r_test.c $(many_sections_test_SOURCES) \ $(object_unittest_SOURCES) permission_test.c plugin_test_1.c \ plugin_test_2.c plugin_test_3.c plugin_test_4.c \ @@ -2014,6 +2023,7 @@ LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \ @NATIVE_OR_CROSS_LINKER_TRUE@object_unittest_SOURCES = object_unittest.cc @NATIVE_OR_CROSS_LINKER_TRUE@binary_unittest_SOURCES = binary_unittest.cc +@NATIVE_OR_CROSS_LINKER_TRUE@leb128_unittest_SOURCES = leb128_unittest.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@constructor_test_SOURCES = constructor_test.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@constructor_test_DEPENDENCIES = gcctestdir/ld @GCC_TRUE@@NATIVE_LINKER_TRUE@constructor_test_LDFLAGS = -Bgcctestdir/ @@ -2942,6 +2952,9 @@ justsyms_exec$(EXEEXT): $(justsyms_exec_OBJECTS) $(justsyms_exec_DEPENDENCIES) large$(EXEEXT): $(large_OBJECTS) $(large_DEPENDENCIES) @rm -f large$(EXEEXT) $(large_LINK) $(large_OBJECTS) $(large_LDADD) $(LIBS) +leb128_unittest$(EXEEXT): $(leb128_unittest_OBJECTS) $(leb128_unittest_DEPENDENCIES) + @rm -f leb128_unittest$(EXEEXT) + $(CXXLINK) $(leb128_unittest_OBJECTS) $(leb128_unittest_LDADD) $(LIBS) @GCC_FALSE@local_labels_test$(EXEEXT): $(local_labels_test_OBJECTS) $(local_labels_test_DEPENDENCIES) @GCC_FALSE@ @rm -f local_labels_test$(EXEEXT) @GCC_FALSE@ $(LINK) $(local_labels_test_OBJECTS) $(local_labels_test_LDADD) $(LIBS) @@ -3322,6 +3335,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/justsyms_1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/justsyms_exec.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/large-large.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/leb128_unittest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/local_labels_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/many_sections_r_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/many_sections_test.Po@am__quote@ @@ -3749,6 +3763,8 @@ object_unittest.log: object_unittest$(EXEEXT) @p='object_unittest$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) binary_unittest.log: binary_unittest$(EXEEXT) @p='binary_unittest$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +leb128_unittest.log: leb128_unittest$(EXEEXT) + @p='leb128_unittest$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) icf_virtual_function_folding_test.log: icf_virtual_function_folding_test$(EXEEXT) @p='icf_virtual_function_folding_test$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) basic_test.log: basic_test$(EXEEXT) diff --git a/gold/testsuite/leb128_unittest.cc b/gold/testsuite/leb128_unittest.cc new file mode 100644 index 0000000000..05c7093757 --- /dev/null +++ b/gold/testsuite/leb128_unittest.cc @@ -0,0 +1,88 @@ +// leb_unittest.cc -- test read_signed_LEB_128 and read_unsigned_LEB_128 + +// Copyright 2012 Free Software Foundation, Inc. +// Written by Cary Coutant . + +// This file is part of gold. + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +// MA 02110-1301, USA. + +#include "gold.h" + +#include + +#include "int_encoding.h" + +#include "test.h" + +namespace gold_testsuite +{ + +using namespace gold; + +bool +Leb128_test(Test_report*) +{ + size_t len; + + // Unsigned tests. + static unsigned char u1[] = { 0 }; // 0 + static unsigned char u2[] = { 1 }; // 1 + static unsigned char u3[] = { 126 }; // 126 + static unsigned char u4[] = { 127 }; // 127 + static unsigned char u5[] = { 0x80+0, 1 }; // 128 + static unsigned char u6[] = { 0x80+1, 1 }; // 129 + static unsigned char u7[] = { 0x80+57, 100 }; // 12857 + static unsigned char u8[] = { 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, + 0x80, 1}; // 1ULL << 63 + + // Signed tests. + static unsigned char s1[] = { 0 }; // 0 + static unsigned char s2[] = { 1 }; // 1 + static unsigned char s3[] = { 0x7e }; // -2 + static unsigned char s4[] = { 0x80+127, 0 }; // 127 + static unsigned char s5[] = { 0x80+1, 0x7f }; // -127 + static unsigned char s6[] = { 0x80+0, 1 }; // 128 + static unsigned char s7[] = { 0x80+0, 0x7f }; // -128 + static unsigned char s8[] = { 0x80+1, 1 }; // 129 + static unsigned char s9[] = { 0xff, 0x7e }; // -129 + + CHECK(read_unsigned_LEB_128(u1, &len) == 0 && len == sizeof(u1)); + CHECK(read_unsigned_LEB_128(u2, &len) == 1 && len == sizeof(u2)); + CHECK(read_unsigned_LEB_128(u3, &len) == 126 && len == sizeof(u3)); + CHECK(read_unsigned_LEB_128(u4, &len) == 127 && len == sizeof(u4)); + CHECK(read_unsigned_LEB_128(u5, &len) == 128 && len == sizeof(u5)); + CHECK(read_unsigned_LEB_128(u6, &len) == 129 && len == sizeof(u6)); + CHECK(read_unsigned_LEB_128(u7, &len) == 12857 && len == sizeof(u7)); + CHECK(read_unsigned_LEB_128(u8, &len) == (1ULL << 63) && len == sizeof(u8)); + + CHECK(read_signed_LEB_128(s1, &len) == 0 && len == sizeof(s1)); + CHECK(read_signed_LEB_128(s2, &len) == 1 && len == sizeof(s2)); + CHECK(read_signed_LEB_128(s3, &len) == -2 && len == sizeof(s3)); + CHECK(read_signed_LEB_128(s4, &len) == 127 && len == sizeof(s4)); + CHECK(read_signed_LEB_128(s5, &len) == -127 && len == sizeof(s5)); + CHECK(read_signed_LEB_128(s6, &len) == 128 && len == sizeof(s6)); + CHECK(read_signed_LEB_128(s7, &len) == -128 && len == sizeof(s7)); + CHECK(read_signed_LEB_128(s8, &len) == 129 && len == sizeof(s8)); + CHECK(read_signed_LEB_128(s9, &len) == -129 && len == sizeof(s9)); + + return true; +} + +Register_test leb128_register("LEB128", Leb128_test); + +} // End namespace gold_testsuite. -- cgit v1.2.1