[libc-commits] [PATCH] D79192: [libc] Add integration tests.

Paula Toth via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Apr 30 11:47:50 PDT 2020


PaulkaToast created this revision.
PaulkaToast added reviewers: sivachandra, abrachet.
PaulkaToast added a project: libc-project.
Herald added subscribers: libc-commits, tschuett, jfb, mgorny.

This patch aims to add integration tests to check the following:

1. Header files are generated as expected.
2. Libc functions have the correct public name.
3. Libc functions have the correct return type and parameter types.
4. Symbols are exposed in the public lib.a files.

This patch uses the TableGen specs to generate two test files for each entrypoint that instantiate a function wrapper to the libc implementations.

One of the test files is compiled against the generated public headers and linked against llvm-libc's lib.a files using compiler options `-nostdinc` and linker options `-nostdlib` to prevent accidentally including our internal headers and any system headers. This is done to ensure that we have successful generated the public headers and that the symbols are exposed.

  #include "Functional.h"
  #include <string.h>
  
  int main() {
    __llvm_libc::cpp::function<char *(char *__restrict, const char *__restrict)> f(strcpy);
    (void) f;
    return 0;
  }

The other test file generated is compiled against the internal headers and links with the internal object files. This ensures that the implementations prototype information matches what is specified in the TableGen files. This is needed as the type information is lost once compiled into the public libraries.

  #include "Functional.h"
  #include "src/string/strcpy.h"
  
  int main() {
    __llvm_libc::cpp::function<char *(char *__restrict, const char *__restrict)> f(__llvm_libc::strcpy);
    (void) f;
    return 0;
  }

For Example:
If there is a mismatch in the number of parameters this error is now produced:

  llvm-project/libc/utils/CPP/Functional.h:22:59: error: cannot initialize a member subobject of type 'char *(*)(char *, const char *)' with an lvalue of type 'char *(char *)': different number of parameters (2 vs 1)
    template <typename Func> constexpr function(Func &&f) : func(f) {}
                                                            ^    ~
  projects/libc/test/src/string/libc.test.src.string.strcpy_integration_test-public-test.cpp:5:80: note: in instantiation of function template specialization '__llvm_libc::cpp::function<char *(char *, const char *)>::function<char *(&)(char *)>' requested here
    __llvm_libc::cpp::function<char *(char *__restrict, const char *__restrict)> f(strcpy);


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79192

Files:
  libc/cmake/modules/LLVMLibCLibraryRules.cmake
  libc/cmake/modules/LLVMLibCTestRules.cmake
  libc/test/src/assert/CMakeLists.txt
  libc/test/src/math/CMakeLists.txt
  libc/test/src/string/CMakeLists.txt
  libc/test/src/string/memory_utils/CMakeLists.txt
  libc/utils/HdrGen/CMakeLists.txt
  libc/utils/HdrGen/PrototypeTestGen/CMakeLists.txt
  libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
  libc/utils/HdrGen/PublicAPICommand.cpp
  libc/utils/HdrGen/PublicAPICommand.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79192.261287.patch
Type: text/x-patch
Size: 20890 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20200430/9e282da0/attachment-0001.bin>


More information about the libc-commits mailing list