-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (181 loc) · 8.14 KB
/
bench-test.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: bench-test
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
project:
[
commonlibrary_rust_ylong_http,
commonlibrary_rust_ylong_json,
commonlibrary_rust_ylong_runtime,
communication_ipc,
hiviewdfx_hilog,
hiviewdfx_hisysevent,
hiviewdfx_hitrace,
request_request,
systemabilitymgr_safwk,
systemabilitymgr_samgr,
]
steps:
- name: clone repo
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 3
retry_on: error
command: git clone https://gitee.com/openharmony/${{ matrix.project }}.git
- name: initialize counters
working-directory: ./${{ matrix.project }}
run: |
echo "for_loop_count_after=0" >> $GITHUB_ENV
echo "for_loop_count_after_in_file=0" >> $GITHUB_ENV
echo "iter_count=0" >> $GITHUB_ENV
echo "iter_count_after=0" >> $GITHUB_ENV
echo "iter_count_in_file=0" >> $GITHUB_ENV
echo "iter_count_after_in_file=0" >> $GITHUB_ENV
echo "iter_mut_count=0" >> $GITHUB_ENV
echo "iter_mut_count_after=0" >> $GITHUB_ENV
echo "iter_mut_count_in_file=0" >> $GITHUB_ENV
echo "iter_mut_count_after_in_file=0" >> $GITHUB_ENV
echo "into_iter_count=0" >> $GITHUB_ENV
echo "into_iter_count_after=0" >> $GITHUB_ENV
echo "into_iter_count_in_file=0" >> $GITHUB_ENV
echo "into_iter_count_after_in_file=0" >> $GITHUB_ENV
echo "par_iter_count=0" >> $GITHUB_ENV
echo "into_par_iter_count=0" >> $GITHUB_ENV
echo "par_iter_mut_count=0" >> $GITHUB_ENV
echo "par_iter_count_in_file=0" >> $GITHUB_ENV
echo "into_par_iter_count_in_file=0" >> $GITHUB_ENV
echo "par_iter_mut_count_in_file=0" >> $GITHUB_ENV
- name: count for loops
working-directory: ./${{ matrix.project }}
shell: bash
run: |
echo "for_loop_count=0" >> $GITHUB_ENV
find . -type f -name '*.rs' | while read -r file; do
echo "Checking $file"
echo "Count in file: $(grep -oE 'for\s+(\([^)]+\)|\w+)\s+in\s+[^{]+' "$file" | wc -l)"
((for_loop_count += for_loop_count_in_file))
done
echo "for loop occurrences: $for_loop_count"
- name: count iterator methods
working-directory: ./${{ matrix.project }}
shell: bash
run: |
# Initialize counters
iter_count=0
iter_mut_count=0
into_iter_count=0
# Iterate over all .rs files in the current directory and subdirectories
while read -r file; do
echo checking $file
# Count occurrences of iterator methods in the current file
iter_count_in_file=$(grep -o '\.iter()' "$file" | wc -l)
iter_mut_count_in_file=$(grep -o '\.iter_mut()' "$file" | wc -l)
into_iter_count_in_file=$(grep -o '\.into_iter()' "$file" | wc -l)
# Update total counters
((iter_count += iter_count_in_file))
((iter_mut_count += iter_mut_count_in_file))
((into_iter_count += into_iter_count_in_file))
done < <(find . -type f -name '*.rs')
# Print results
echo ".iter() occurrences: $iter_count"
echo ".iter_mut() occurrences: $iter_mut_count"
echo ".into_iter() occurrences: $into_iter_count"
- name: add Cargo.toml dylint lib link
working-directory: ./${{ matrix.project }}
run: echo -e "\n[workspace.metadata.dylint]\nlibraries = [\n { git = \"https://github.com/trusted-programming/cargo-mate\"},\n]" >> Cargo.toml
- name: add rayon
working-directory: ./${{ matrix.project }}
shell: bash
run: |
find . -type f -name "Cargo.toml" | while read -r file; do
# Check if there is a [package] section in the file
if grep -qE "^\[package\]" "$file"; then
# Check if rayon is already in the dependencies
if ! grep -qE "^rayon =" "$file"; then
# Check if [dependencies] section exists
if ! grep -qE "^\[dependencies\]" "$file"; then
# Add [dependencies] section at the end of the file
echo -e "\n[dependencies]" >> "$file"
fi
# Add rayon under the [dependencies] line
sed -i '/\[dependencies\]/a rayon = "1.8.1"' "$file"
fi
fi
done
- name: install dylint
run: cargo install cargo-dylint dylint-link
- name: lint fix
working-directory: ./${{ matrix.project }}
continue-on-error: true
run: cargo dylint --all --workspace --fix -- --allow-dirty --allow-no-vcs --broken-code --lib
- name: cargo check
working-directory: ./${{ matrix.project }}
continue-on-error: true
run: cargo check
- name: git diff for .rs files
working-directory: ./${{ matrix.project }}
run: git diff -- '*.rs'
- name: count for loops after tool
working-directory: ./${{ matrix.project }}
shell: bash
run: |
while read -r file; do
echo "Checking $file"
for_loop_count_after_in_file=$(grep -oE 'for\s+(\([^)]+\)|\w+)\s+in\s+[^{]+' "$file" | wc -l)
echo "Count in file: $for_loop_count_after_in_file"
((for_loop_count_after += for_loop_count_after_in_file))
done < <(find . -type f -name '*.rs')
echo "for loop occurrences: $for_loop_count_after"
- name: count iterator methods after tool
working-directory: ./${{ matrix.project }}
shell: bash
run: |
# Initialize counters
iter_count_after=0
iter_mut_count_after=0
into_iter_count_after=0
# Iterate over all .rs files in the current directory and subdirectories
while read -r file; do
echo checking $file
# Count occurrences of iterator methods in the current file
iter_count_after_in_file=$(grep -o '\.iter()' "$file" | wc -l)
iter_mut_count_after_in_file=$(grep -o '\.iter_mut()' "$file" | wc -l)
into_iter_count_after_in_file=$(grep -o '\.into_iter()' "$file" | wc -l)
# Update total counters
((iter_count_after += iter_count_after_in_file))
((iter_mut_count_after += iter_mut_count_after_in_file))
((into_iter_count_after += into_iter_count_after_in_file))
done < <(find . -type f -name '*.rs')
# Print results
echo ".iter() occurrences: $iter_count_after"
echo ".iter_mut() occurrences: $iter_mut_count_after"
echo ".into_iter() occurrences: $into_iter_count_after"
- name: par iter count
working-directory: ./${{ matrix.project }}
shell: bash
run: |
# Initialize counters
par_iter_count=0
into_par_iter_count=0
par_iter_mut_count=0
# Iterate over all .rs files in the current directory and subdirectories
while read -r file; do
echo checking $file
# Count occurrences in the current file
par_iter_count_in_file=$(grep -o '\.par_iter()' "$file" | wc -l)
into_par_iter_count_in_file=$(grep -o '\.into_par_iter()' "$file" | wc -l)
par_iter_mut_count_in_file=$(grep -o '\.par_iter_mut()' "$file" | wc -l)
# Update total counters
((par_iter_count += par_iter_count_in_file))
((into_par_iter_count += into_par_iter_count_in_file))
((par_iter_mut_count += par_iter_mut_count_in_file))
done < <(find . -type f -name '*.rs')
# Print results
echo ".par_iter() occurrences: $par_iter_count"
echo ".into_par_iter() occurrences: $into_par_iter_count"
echo ".par_iter_mut() occurrences: $par_iter_mut_count"