Skip to content

Commit

Permalink
test: Update lib_dlopen2 test case (t200)
Browse files Browse the repository at this point in the history
It has a couple problems.  First, the filter should be set for the main
function, there's no function called 'a'.  And the 'creat' function is
not the syscall so it should not fix up it to match creat64 in libc.

Finally, it seems GCC optimized out the Parent construction as it does
nothing.  clang seems to keep it, so let's handle it in the fixup().

The failed output looked like below:
    t200_lib_dlopen2: diff result of g++ -pg -O1 -g -fno-ipa-sra
    --- expect	2024-03-02 12:33:32.381859085 -0800
    +++ result	2024-03-02 12:33:32.381859085 -0800
    @@ -3,7 +3,5 @@
        dlsym();
    -   creat64() {
    -     Child::Child() {
    -       Parent::Parent();
    -     } /* Child::Child */
    -   } /* creat64 */
    +   creat() {
    +     Child::Child();
    +   } /* creat */
        Child::func();

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Mar 2, 2024
1 parent 2916435 commit 026d456
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions tests/s-dlopen2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Parent {
int main(int argc, char *argv[])
{
void *handle;
Parent *(*creat)();
Parent *(*create)();
Parent *p;
int n = 1;

Expand All @@ -23,9 +23,9 @@ int main(int argc, char *argv[])
if (!handle)
return -1;

creat = (Parent * (*)()) dlsym(handle, "creat");
p = creat();
p->bar(n);
create = (Parent * (*)()) dlsym(handle, "create");
p = create();
p->bar(n); // calls func() which is defined in Child
dlclose(handle);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/s-libbaz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int Child::func(int n)
return 100;
}

extern "C" Parent *creat()
extern "C" Parent *create()
{
return new Child;
}
13 changes: 9 additions & 4 deletions tests/t200_lib_dlopen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def __init__(self):
[ 29510] | main() {
398.509 us [ 29510] | dlopen();
2.324 us [ 29510] | dlsym();
[ 29510] | creat() {
[ 29510] | create() {
[ 29510] | Child::Child() {
0.290 us [ 29510] | Parent::Parent();
1.703 us [ 29510] | } /* Child::Child */
6.090 us [ 29510] | } /* creat */
6.090 us [ 29510] | } /* create */
0.133 us [ 29510] | Child::func();
48.519 us [ 29510] | dlclose();
465.432 us [ 29510] | } /* main */
Expand All @@ -33,7 +33,12 @@ def build(self, name, cflags='', ldflags=''):
cflags, ldflags)

def setup(self):
self.option = '-F a'
self.option = '-F main'

def fixup(self, cflags, result):
return result.replace('creat', 'creat64')
# GCC seems to optimize out the empty Parent::Parent().
return result.replace("""
[ 29510] | Child::Child() {
0.290 us [ 29510] | Parent::Parent();
1.703 us [ 29510] | } /* Child::Child */""", """
1.703 us [ 29510] | Child::Child();""")

0 comments on commit 026d456

Please sign in to comment.