Skip to content

Commit 9b69db2

Browse files
committed
Add some vt insert and movement tests
1 parent 96c6bb7 commit 9b69db2

File tree

7 files changed

+100
-49
lines changed

7 files changed

+100
-49
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,33 @@ jobs:
2828

2929
check_clang_format:
3030
name: "Check C++ style"
31-
runs-on: ubuntu-22.04
31+
runs-on: ubuntu-24.04
3232
steps:
3333
- uses: actions/checkout@v3
3434
- name: Install clang
3535
run: |
3636
wget https://apt.llvm.org/llvm.sh
3737
chmod +x llvm.sh
38-
sudo ./llvm.sh 17
39-
sudo apt-get install clang-format-17
38+
sudo ./llvm.sh 18
39+
sudo apt-get install clang-format-18
4040
- name: "Clang-format libtermbench"
41-
run: find ./libtermbench -name "*.cpp" -o -name "*.h" | xargs clang-format-17 --Werror --dry-run
41+
run: find ./libtermbench -name "*.cpp" -o -name "*.h" | xargs clang-format-18 --Werror --dry-run
4242
- name: "Clang-format tb"
43-
run: find ./tb -name "*.cpp" -o -name "*.h" | xargs clang-format-17 --Werror --dry-run
43+
run: find ./tb -name "*.cpp" -o -name "*.h" | xargs clang-format-18 --Werror --dry-run
4444
- name: "Check includes"
4545
run: ./scripts/check-includes.sh
4646

4747
ubuntu_linux:
48-
name: "Ubuntu Linux 22.04"
49-
runs-on: ubuntu-22.04
48+
name: "Ubuntu Linux 24.04"
49+
runs-on: ubuntu-24.04
5050
env:
5151
CMAKE_PRESET: "linux-gcc-release"
5252
steps:
5353
- uses: actions/checkout@v3
5454
- name: ccache
5555
uses: hendrikmuhs/ccache-action@v1
5656
with:
57-
key: "ccache-ubuntu_2204"
57+
key: "ccache-ubuntu_2404"
5858
max-size: 256M
5959
- name: set environment variables
6060
id: set_vars
@@ -67,18 +67,18 @@ jobs:
6767
sudo apt -q update
6868
sudo apt install -qy ninja-build
6969
sudo ./scripts/install-deps.sh
70-
- name: "Install GCC 13"
71-
run: sudo apt install g++-13
70+
- name: "Install GCC"
71+
run: sudo apt install g++
7272
- name: "cmake"
73-
run: cmake --preset "$CMAKE_PRESET" -D CMAKE_CXX_COMPILER="g++-13"
73+
run: cmake --preset "$CMAKE_PRESET" -D CMAKE_CXX_COMPILER="g++"
7474
- name: "build"
7575
run: cmake --build --preset "$CMAKE_PRESET" --preset -- -j3
7676
- name: "install dependencies for running benchmarks"
7777
run: ./scripts/xvfb-deps.sh
7878
- name: "Install contour"
7979
run: |
80-
wget https://github.com/contour-terminal/contour/releases/download/v$CONTOUR_VERSION/contour-$CONTOUR_VERSION-ubuntu22.04-amd64.deb
81-
sudo dpkg -i contour-$CONTOUR_VERSION-ubuntu22.04-amd64.deb
80+
wget https://github.com/contour-terminal/contour/releases/download/v$CONTOUR_VERSION/contour-$CONTOUR_VERSION-ubuntu24.04-amd64.deb
81+
sudo dpkg -i contour-$CONTOUR_VERSION-ubuntu24.04-amd64.deb
8282
- name: "create and patch contour.yml config file"
8383
run: |
8484
set -ex

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,30 @@ benefit from this library, if not even integrating it.
1313
Adding a C-API binding is considered as soon there is also interest
1414
from other projects that cannot use the C++ API.
1515

16+
17+
## Run tests
18+
To run tests you need to spawn `tb` executable from terminal, for example:
19+
` contour $(pwd)/build/tb/tb --fixed-size --column-by-column --size 2 --output contour_results`
20+
for more info run `tb --hlep`
21+
In folder scripts you can find some convinent scripts for testing different terminals and way to create results afterwards,
22+
you can run
23+
24+
``` sh
25+
./scripts/Xvfb-bench-run.sh $(pwd)/build/tb/tb
26+
julia scripts/plot_results.jl
27+
```
28+
29+
This will run benchmark in background and plot results with julia afterwards
30+
1631
## Test coverage
1732

1833
- [x] long text lines
1934
- [x] short text lines
2035
- [x] text lines with foreground color
2136
- [x] text lines with foreground & background color
22-
- [ ] cursor movement (`CUB`, `CUD`, `CUF`, `CUP`, `CUU`)
37+
- [x] cursor movement (`CUB`, `CUD`, `CUF`, `CUP`, `CUU`)
2338
- [ ] rectangular operations (`DECCRA`, `DECFRA`, `DECERA`)
24-
- [ ] insert lines/columns (`IL`, `DECIC`)
39+
- [x] insert lines/columns (`IL`, `DECIC`)
2540
- [ ] delete lines (`DL`)
2641
- [ ] erase lines/columns (`EL`, `ED`)
2742
- [ ] complex unicode LTR

libtermbench/termbench.cpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ void Benchmark::runAll()
106106

107107
void Benchmark::summarizeToJson(std::ostream& os)
108108
{
109-
std::string buffer = glz::write_json(results_);
110-
os << buffer;
109+
auto buffer = glz::write_json(results_);
110+
os << buffer.value();
111111
}
112112

113113
void Benchmark::summarize(std::ostream& os)
@@ -416,14 +416,14 @@ std::unique_ptr<Test> binary()
416416

417417
std::unique_ptr<Test> ascii_line(size_t line_length)
418418
{
419-
auto name = std::to_string(line_length) + " chars per line";
419+
auto name = std::to_string(line_length) + "_chars_per_line";
420420
auto text = std::string(line_length, 'a') + std::string { "\n" };
421421
return std::make_unique<Line>(name, text);
422422
}
423423

424424
std::unique_ptr<Test> sgr_line(size_t line_length)
425425
{
426-
auto name = std::to_string(line_length) + " chars with sgr per line";
426+
auto name = std::to_string(line_length) + "_chars_with_sgr_per_line";
427427
std::string text {};
428428
text += "\033[38;2;20;200;200m";
429429
text += std::string(line_length, 'a');
@@ -434,7 +434,7 @@ std::unique_ptr<Test> sgr_line(size_t line_length)
434434

435435
std::unique_ptr<Test> sgrbg_line(size_t line_length)
436436
{
437-
auto name = std::to_string(line_length) + " chars with sgr and bg per line";
437+
auto name = std::to_string(line_length) + "_chars_with_sgr_and_bg_per_line";
438438
std::string text {};
439439
text += "\033[38;2;20;200;200m\033[48;2;100;100;100m";
440440
text += std::string(line_length, 'a');
@@ -445,7 +445,7 @@ std::unique_ptr<Test> sgrbg_line(size_t line_length)
445445

446446
std::unique_ptr<Test> unicode_simple(size_t line_length)
447447
{
448-
auto name = std::to_string(line_length) + " unicode simple";
448+
auto name = std::to_string(line_length) + "_unicode_simple";
449449
std::string text {};
450450
for (size_t i = 0; i < line_length; ++i)
451451
text += "\u0061";
@@ -455,7 +455,7 @@ std::unique_ptr<Test> unicode_simple(size_t line_length)
455455

456456
std::unique_ptr<Test> unicode_two_codepoints(size_t line_length)
457457
{
458-
auto name = std::to_string(line_length) + " unicode diacritic";
458+
auto name = std::to_string(line_length) + "_unicode_diacritic";
459459
std::string text {};
460460
for (size_t i = 0; i < line_length; ++i)
461461
text += "\u0061\u0308";
@@ -465,37 +465,57 @@ std::unique_ptr<Test> unicode_two_codepoints(size_t line_length)
465465

466466
std::unique_ptr<Test> unicode_three_codepoints(size_t line_length)
467467
{
468-
auto name = std::to_string(line_length) + " unicode double diacritic";
468+
auto name = std::to_string(line_length) + "_unicode_double_diacritic";
469469
std::string text {};
470470
for (size_t i = 0; i < static_cast<size_t>(line_length / 2); ++i)
471471
text += "\u0061\u035D\u0062";
472472
text += "\n";
473473
return std::make_unique<Line>(name, text);
474474
}
475475

476-
std::unique_ptr<Test> unicode_fire_as_text(size_t line_length)
476+
std::unique_ptr<Test> unicode_fire(size_t line_length)
477477
{
478-
auto name = std::to_string(line_length) + " unicode fire as text";
478+
auto name = std::to_string(line_length) + "_unicode_fire";
479479
std::string text {};
480480
for (size_t i = 0; i < static_cast<size_t>(line_length / 2); ++i)
481-
text += std::string { "\U0001F525\U0000FE0E" };
481+
text += std::string { "\U0001F525" };
482482
text += std::string { "\n" };
483483
return std::make_unique<Line>(name, text);
484484
}
485485

486-
std::unique_ptr<Test> unicode_fire(size_t line_length)
486+
/* Creates rectangular block:
487+
* u --- f
488+
* | |
489+
* b --- d
490+
* with each side being line_length long.
491+
* */
492+
std::unique_ptr<Test> vt_movement(size_t line_length)
487493
{
488-
auto name = std::to_string(line_length) + " unicode fire";
494+
auto name = std::to_string(line_length) + "_vt_movement";
489495
std::string text {};
490-
for (size_t i = 0; i < static_cast<size_t>(line_length / 2); ++i)
491-
text += std::string { "\U0001F525" };
496+
text += std::format("\033[{}Au\033[1D", line_length); // up
497+
text += std::format("\033[{}Cf\033[1D", line_length); // forward
498+
text += std::format("\033[{}Bd\033[1D", line_length); // down
499+
text += std::format("\033[{}Db\033[1D", line_length); // backward
500+
text += std::string { "\n" };
501+
return std::make_unique<Line>(name, text);
502+
}
503+
504+
/* Inserts lines and columns
505+
*/
506+
std::unique_ptr<Test> vt_insert(size_t line_length)
507+
{
508+
auto name = std::to_string(line_length) + "_vt_insert";
509+
std::string text {};
510+
text += std::format("\033[{}L", line_length); // insert lines IL
511+
text += std::format("\033[{}{}", line_length, "'}"); // insert columns DECIC
492512
text += std::string { "\n" };
493513
return std::make_unique<Line>(name, text);
494514
}
495515

496516
std::unique_ptr<Test> unicode_flag(size_t line_length)
497517
{
498-
auto name = std::to_string(line_length) + " unicode flag";
518+
auto name = std::to_string(line_length) + "_unicode_flag";
499519
std::string text {};
500520
std::string flag {};
501521
flag += "\U0001F3F4";

libtermbench/termbench.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ std::unique_ptr<Test> ascii_line(size_t);
164164
std::unique_ptr<Test> sgr_line(size_t);
165165
std::unique_ptr<Test> sgrbg_line(size_t);
166166
std::unique_ptr<Test> unicode_simple(size_t);
167+
std::unique_ptr<Test> vt_movement(size_t);
168+
std::unique_ptr<Test> vt_insert(size_t);
167169
std::unique_ptr<Test> unicode_two_codepoints(size_t);
168170
std::unique_ptr<Test> unicode_three_codepoints(size_t);
169171
std::unique_ptr<Test> unicode_flag(size_t);
170-
std::unique_ptr<Test> unicode_fire_as_text(size_t); // U+FEOE
171172
std::unique_ptr<Test> unicode_fire(size_t);
172173
std::unique_ptr<Test> crafted(std::string name, std::string description, std::string text);
173174
} // namespace termbench::tests

scripts/Xvfb-bench-run.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ function program_exit() {
4949
function bench_terminal() {
5050
printf "\033[1m==> Running terminal: $1\033[m\n"
5151
local terminal_name=$(basename $1)
52-
time "${@}" -e "${TB_BIN}" --fixed-size --column-by-column --size 2 --output "${OUTPUT_DIR}/${terminal_name}_results"
52+
time "${@}" -e "${TB_BIN}" --fixed-size --column-by-column --size 1 --output "${OUTPUT_DIR}/${terminal_name}_results"
5353
local exit_code=$?
5454
printf "\033[1m==> Terminal exit code: $exit_code\033[m\n"
55+
if [[ $exit_code -ne 0 ]]; then
56+
program_exit $exit_code
57+
fi
5558
}
5659

5760
set -x

scripts/plot_results.jl

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Pkg
22
Pkg.add("CairoMakie")
33
Pkg.add("JSON")
4+
Pkg.instantiate()
45
using CairoMakie
56
using JSON
67

@@ -20,23 +21,25 @@ end
2021

2122
function get_values(data, data_type)
2223
if data_type == :ascii
23-
name = "chars per line"
24+
name = "chars_per_line"
2425
elseif data_type == :sgr
25-
name = "chars with sgr per line"
26+
name = "chars_with_sgr_per_line"
2627
elseif data_type == :sgr_bg
27-
name = "chars with sgr and bg per line"
28+
name = "chars_with_sgr_and_bg_per_line"
2829
elseif data_type == :unicode
29-
name = "unicode simple"
30+
name = "unicode_simple"
3031
elseif data_type == :diacritic
31-
name = "unicode diacritic"
32+
name = "unicode_diacritic"
3233
elseif data_type == :diacritic_double
33-
name = "unicode double diacritic"
34+
name = "unicode_double_diacritic"
3435
elseif data_type == :fire
35-
name = "unicode fire"
36-
elseif data_type == :fire_text
37-
name = "unicode fire as text"
36+
name = "unicode_fire"
37+
elseif data_type == :vt_movement
38+
name = "vt_movement"
39+
elseif data_type == :vt_insert
40+
name = "vt_insert"
3841
elseif data_type == :flag
39-
name = "unicode flag"
42+
name = "unicode_flag"
4043
end
4144

4245
lines = Vector{Float64}()
@@ -67,14 +70,14 @@ function generate_for_terminal(file_name, prefix="results_")
6770

6871
data = get_data(file_name)
6972

70-
markers = [:circle :rect :cross :star4 :start5 :star6 :diamond]
73+
markers = [:circle :rect :cross :star4 :star5 :star6 :diamond]
7174

7275
get_values_l = (type) -> get_values(data,type)
7376
speed = [ get_values_l(t) for t in types]
7477

7578
marker_size = 8
7679
for (ind,dat) in enumerate(speed)
77-
scatter!(ax,dat, label= terminal_name * "_" * string(types[ind]), marker = markers[ind], markersize = marker_size)
80+
scatter!(ax, dat,label= terminal_name * "_" * string(types[ind]), marker = markers[ind], markersize = marker_size)
7881
end
7982
axislegend(position = :rt)
8083

@@ -108,13 +111,21 @@ generate_for_terminal("alacritty_results")
108111
generate_for_terminal("xterm_results")
109112
generate_for_terminal("kitty_results")
110113
generate_for_terminal("wezterm_results")
111-
types = [:unicode :fire :flag :diacritic :diacritic_double :fire_text]
114+
types = [:unicode :fire :flag :diacritic :diacritic_double]
112115
generate_for_terminal_l = (n) -> generate_for_terminal(n, "results_unicode_")
113116
generate_for_terminal_l("contour_results")
114117
generate_for_terminal_l("alacritty_results")
115118
generate_for_terminal_l("xterm_results")
116119
generate_for_terminal_l("kitty_results")
117120
generate_for_terminal_l("wezterm_results")
121+
types = [:vt_movement :vt_insert]
122+
generate_for_terminal_l = (n) -> generate_for_terminal(n, "results_vt_")
123+
generate_for_terminal_l("contour_results")
124+
generate_for_terminal_l("alacritty_results")
125+
generate_for_terminal_l("xterm_results")
126+
generate_for_terminal_l("kitty_results")
127+
generate_for_terminal_l("wezterm_results")
128+
118129

119-
types = [:ascii :sgr :sgr_bg :unicode :fire :fire_text :flag :diacritic :diacritic_double]
130+
types = [:ascii :sgr :sgr_bg :unicode :fire :flag :diacritic :diacritic_double :vt_movement :vt_insert]
120131
[ save("comparison_"*string(type)*".png", generate_comparison(type)) for type in types ]

tb/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct TestsToRun
122122
struct BenchSettings
123123
{
124124
TerminalSize requestedTerminalSize {};
125-
size_t testSizeMB = 32;
125+
size_t testSizeMB = 1;
126126
bool nullSink = false;
127127
bool stdoutFastPath = false;
128128
std::vector<std::filesystem::path> craftedTests {};
@@ -252,11 +252,12 @@ bool addTestsToBenchmark(termbench::Benchmark& tb, BenchSettings const& settings
252252
add_test(termbench::tests::unicode_simple);
253253
add_test(termbench::tests::unicode_two_codepoints);
254254
add_test(termbench::tests::unicode_three_codepoints);
255-
add_test(termbench::tests::unicode_fire_as_text);
256255
add_test(termbench::tests::unicode_fire);
257256
add_test(termbench::tests::unicode_flag);
258257
add_test(termbench::tests::sgr_line);
259258
add_test(termbench::tests::sgrbg_line);
259+
add_test(termbench::tests::vt_movement);
260+
add_test(termbench::tests::vt_insert);
260261
}
261262
return true;
262263
}

0 commit comments

Comments
 (0)