• Thomas Richter's avatar
    perf test: Fix 'Simple expression parser' test on arch without CPU die topology info · 6c481031
    Thomas Richter authored
    Some platforms do not have CPU die support, for example s390.
    
    Commit
    Cc: Ian Rogers <irogers@google.com>
    Fixes: fdf1e29b ("perf expr: Add metric literals for topology.")
    fails on s390:
    
      # perf test -Fv 7
        ...
      # FAILED tests/expr.c:173 #num_dies >= #num_packages
        ---- end ----
        Simple expression parser: FAILED!
      #
    
    Investigating this issue leads to these functions:
    
     build_cpu_topology()
       +--> has_die_topology(void)
            {
               struct utsname uts;
    
               if (uname(&uts) < 0)
                      return false;
               if (strncmp(uts.machine, "x86_64", 6))
                      return false;
               ....
            }
    
    which always returns false on s390. The caller build_cpu_topology()
    checks has_die_topology() return value. On false the the struct
    cpu_topology::die_cpu_list is not contructed and has zero entries. This
    leads to the failing comparison: #num_dies >= #num_packages.  s390 of
    course has a positive number of packages.
    
    Fix this and check if the function build_cpu_topology() did build up
    a die_cpus_list. The number of entries in this list should be larger
    than 0. If the number of list element is zero, the die_cpus_list has
    not been created and the check in function test__expr():
    
        TEST_ASSERT_VAL("#num_dies >= #num_packages", \
    		    num_dies >= num_packages)
    
    always fails.
    
    Output after:
    
      # perf test -Fv 7
       7: Simple expression parser                                        :
       --- start ---
       division by zero
       syntax error
       ---- end ----
       Simple expression parser: Ok
      #
    
    Fixes: fdf1e29b ("perf expr: Add metric literals for topology.")
    Signed-off-by: default avatarThomas Richter <tmricht@linux.ibm.com>
    Acked-by: default avatarIan Rogers <irogers@google.com>
    Cc: Heiko Carstens <hca@linux.ibm.com>
    Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
    Cc: Sven Schnelle <svens@linux.ibm.com>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Link: http://lore.kernel.org/lkml/20211129112339.3003036-1-tmricht@linux.ibm.com
    [ Added comment in the added 'if (num_dies)' line about architectures not having die topology ]
    Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    6c481031
expr.c 6.05 KB