From 0c5bee8fdd40bbbad9d3f5cce06785c72632fbd0 Mon Sep 17 00:00:00 2001 From: Bryan Chan Date: Fri, 27 Dec 2019 17:26:24 -0500 Subject: [PATCH] [test] do not parse ls output for file size; NFCI Parsing `ls -l` output to obtain the size of a file is unreliable; the exact output format is not specified, and some user or group names may contain multiple words, causing `cut -f5 -d' '` to extract an incorrect value. `wc -c`, on the other hand, is portable, and there are precendents of its use in test cases. --- llvm/test/tools/llvm-profdata/show-prof-size.test | 2 +- llvm/test/tools/yaml2obj/ELF/custom-null-section.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/test/tools/llvm-profdata/show-prof-size.test b/llvm/test/tools/llvm-profdata/show-prof-size.test index cc9b16aa08cc3..a77360c8a673d 100644 --- a/llvm/test/tools/llvm-profdata/show-prof-size.test +++ b/llvm/test/tools/llvm-profdata/show-prof-size.test @@ -1,5 +1,5 @@ ; RUN: llvm-profdata merge -sample -extbinary -prof-sym-list=%S/Inputs/profile-symbol-list-1.text %S/Inputs/sample-profile.proftext -o %t.1.output -; RUN: ls -l %t.1.output |tr -s ' ' |cut -f5 -d ' ' > %t.txt +; RUN: wc -c < %t.1.output > %t.txt ; RUN: llvm-profdata show -sample -show-sec-info-only %t.1.output >> %t.txt ; RUN: FileCheck %s --input-file=%t.txt ; Check llvm-profdata shows the correct file size. diff --git a/llvm/test/tools/yaml2obj/ELF/custom-null-section.yaml b/llvm/test/tools/yaml2obj/ELF/custom-null-section.yaml index e8cbb4edb630f..93346032b7953 100644 --- a/llvm/test/tools/yaml2obj/ELF/custom-null-section.yaml +++ b/llvm/test/tools/yaml2obj/ELF/custom-null-section.yaml @@ -71,8 +71,8 @@ Sections: ## of the first SHT_NULL section. # RUN: yaml2obj --docnum=4 %s -o %t4 -# RUN: ls -l %t3 | tr -s ' ' | cut -d ' ' -f 5 > %t.txt -# RUN: ls -l %t4 | tr -s ' ' | cut -d ' ' -f 5 >> %t.txt +# RUN: wc -c < %t3 > %t.txt +# RUN: wc -c < %t4 >> %t.txt # RUN: FileCheck %s --input-file=%t.txt --check-prefix=SIZE # SIZE: [[FILESIZE:.*]]