[libc-commits] [PATCH] D74652: [libc] Add support library for use with tests.

Alex Brachet via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Feb 14 17:42:52 PST 2020


abrachet added a comment.

I was actually just working on a patch to add death tests, so I have a lot of thoughts on this :)

We could do something like:

name=header.h
  struct PolymorphicFunction {
    virtual ~PolymorphicFunction() {}
    virtual void call() = 0;
  };
  
  void doDeathTest(PolymorphicFunction &);
  
  template <typename Func>
  void createPolyFunction(Func f) {
     struct F : public PolymorphicFunction {
        Func f;
        F(Func f) : f(f) {}
        void call() override {
           f();
        }
     };
     F polyFunc(f);
     // For forking death teast stack allocation was fine but for thread we can't do that.
     doDeathTest(f);
  }

So that in tests we can use lambdas, even ones which have a capture. What do you think about something like that? A Thread class could hold `PolymorphicFunction *` for example.



================
Comment at: libc/utils/testutils/Thread.h:13-14
+
+  explicit Thread(FuncTypeNoArg &&F);
+  explicit Thread(FuncTypeOneArg &&F, void *Arg);
+
----------------
I think these are not very ergonomic because they cannot be instantiated with lambdas. See my top level comment how I think we can do this better.


================
Comment at: libc/utils/testutils/linux/sleep.cpp:7
+
+int sleep(unsigned int Seconds) { return ::sleep(Seconds); }
+
----------------
Out of curiosity, why have you added sleep? Where do you think it will be useful?



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74652/new/

https://reviews.llvm.org/D74652





More information about the libc-commits mailing list