Save screenshots to PNG, make tests compare screenshots.

This commit is contained in:
Ivan Baravy 2020-02-19 03:27:18 +03:00
parent 759b526b3d
commit b2819b485b
28 changed files with 8520 additions and 40 deletions

5
.gitignore vendored
View File

@ -11,7 +11,7 @@ mkfilepattern
*.img.gz *.img.gz
*.img.lz4 *.img.lz4
*.img.info *.img.info
t_*.out *.out.???
.gdb_history .gdb_history
umka.fas umka.fas
umka.sym umka.sym
@ -21,7 +21,4 @@ tags
*.out *.out
coverage.* coverage.*
covpreproc covpreproc
*.rgba
*.rgb
*.png
*.skn *.skn

14
README
View File

@ -5,7 +5,7 @@ This is a common project for a set of KolibriOS developer tools which are based
on original KolibriOS code wrapped and hacked as to run in the UNIX programming on original KolibriOS code wrapped and hacked as to run in the UNIX programming
environment. The idea is to make userspace UNIX tools that use as much unchanged environment. The idea is to make userspace UNIX tools that use as much unchanged
KolibriOS source as possible to test architecture-independent parts of the KolibriOS source as possible to test architecture-independent parts of the
kernelin your favorite developer environment. kernel in your favorite developer environment.
umka_shell umka_shell
@ -43,10 +43,14 @@ Framebuffer can be dumped to disk as image file.
Troubleshooting Troubleshooting
--------------- ---------------
gm convert -size 400x300 -depth 8 umka.rgba umka.png No troubles -- no shooting.
Links Links & Acknowledgements
----- ------------------------
[1] https://github.com/libfuse/libfuse [1] Filesystem in Userspace library
https://github.com/libfuse/libfuse
[2] LodePNG by Lode Vandevenne
https://lodev.org/lodepng/

6398
lodepng.c Normal file

File diff suppressed because it is too large Load Diff

1945
lodepng.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
FASM=fasm FASM=fasm
CC=gcc CC=gcc
WARNINGS=-Wall -Wextra -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -Wnull-dereference -Wjump-misses-init -Wshadow -Wformat=2 -Wswitch -Wswitch-enum #-Wconversion -Wsign-conversion WARNINGS=-Wall -Wextra -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -Wnull-dereference -Wjump-misses-init -Wshadow -Wformat=2 -Wswitch #-Wswitch-enum #-Wconversion -Wsign-conversion
CFLAGS=$(WARNINGS) -g -O0 -D_FILE_OFFSET_BITS=64 -Wno-address-of-packed-member -DNDEBUG -masm=intel CFLAGS=$(WARNINGS) -g -O0 -D_FILE_OFFSET_BITS=64 -Wno-address-of-packed-member -DNDEBUG -masm=intel
CFLAGS_32=-m32 CFLAGS_32=$(CFLAGS) -m32
LDFLAGS= LDFLAGS=
LDFLAGS_32=-m32 LDFLAGS_32=-m32
@ -11,7 +11,7 @@ all: umka_shell umka_fuse umka.sym umka.prp umka.lst tags tools/mkdirrange tools
covpreproc: covpreproc.c covpreproc: covpreproc.c
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
umka_shell: umka_shell.o umka.o trace.o trace_lbr.o cio.o umka_shell: umka_shell.o umka.o trace.o trace_lbr.o cio.o lodepng.o
$(CC) $(LDFLAGS) $(LDFLAGS_32) $^ -o $@ -static $(CC) $(LDFLAGS) $(LDFLAGS_32) $^ -o $@ -static
umka_fuse: umka_fuse.o umka.o cio.o umka_fuse: umka_fuse.o umka.o cio.o
@ -20,6 +20,9 @@ umka_fuse: umka_fuse.o umka.o cio.o
umka.o umka.fas: umka.asm skin.skn umka.o umka.fas: umka.asm skin.skn
INCLUDE="$(KOLIBRI)/kernel/trunk;$(KOLIBRI)/programs/develop/libraries/libcrash/trunk" $(FASM) $< umka.o -s umka.fas -m 1234567 INCLUDE="$(KOLIBRI)/kernel/trunk;$(KOLIBRI)/programs/develop/libraries/libcrash/trunk" $(FASM) $< umka.o -s umka.fas -m 1234567
lodepng.o: lodepng.c lodepng.h
$(CC) $(CFLAGS_32) -c $<
skin.skn: $(KOLIBRI)/skins/Leency/Octo_flat/default.asm skin.skn: $(KOLIBRI)/skins/Leency/Octo_flat/default.asm
$(FASM) $< $@ $(FASM) $< $@

View File

@ -119,6 +119,17 @@ static inline void umka_sys_draw_rect(size_t x, size_t xsize,
: "memory"); : "memory");
} }
static inline void umka_sys_get_screen_size(uint32_t *xsize, uint32_t *ysize) {
uint32_t xysize;
__asm__ __inline__ __volatile__ (
"call i40"
: "=a"(xysize)
: "a"(14)
: "memory");
*xsize = (xysize >> 16) + 1;
*ysize = (xysize & 0xffffu) + 1;
}
static inline void umka_sys_draw_line(size_t x, size_t xend, static inline void umka_sys_draw_line(size_t x, size_t xend,
size_t y, size_t yend, size_t y, size_t yend,
uint32_t color, int invert) { uint32_t color, int invert) {

View File

@ -0,0 +1,108 @@
/> disk_add ../img/kolibri.img rd
/rd/1: fat
/> set_skin /sys/DEFAULT.SKN
status: 0
/> window_redraw 1
/> draw_window 0 300 0 200 0x000088 1 1 1 0 1 4 hello
/> set_pixel 0 0 0x0000ff
/> set_pixel 1 1 0xff0000
/> set_pixel 2 2 0x00ff00
/> draw_line 10 510 10 510 0xff0000
/> draw_rect 60 20 30 20 0x00ff00
/> put_image chess_image.rgb 8 8 5 15
/> put_image_palette chess_image.rgb 12 12 5 30 9 0
/> write_text 10 70 0xffff00 hello 0 0 0 0 0 5 0
/> set_button_style 0
/> button 55 40 5 20 0xc0ffee 0xffffff 1 0
/> set_button_style 1
/> button 100 40 5 20 0xc1ffee 0xffffff 1 0
/> display_number 0 10 4 0 0 1234 5 45 0xffff00 1 1 0 0 0x0000ff
/> blit_bitmap chess_image.rgba 20 35 8 8 0 0 8 8 0 0 0 1 32
/> window_redraw 2
/> set_window_caption hi_there 0
/> move_window 220 35 150 200
/> get_font_smoothing
font smoothing: 2 - subpixel
/> set_font_smoothing 0
/> get_font_smoothing
font smoothing: 0 - off
/> get_window_colors
0x00586786 frame
0x00fefefe grab
0x00aea6a6 work_3d_dark
0x00fbfbfb work_3d_light
0x00333333 grab_text
0x00ddd7cf work
0x007887a6 work_button
0x00fefefe work_button_text
0x00000000 work_text
0x007e7e7e work_graph
/> set_window_colors 0 0 0 0 0 0 0 0 0 0
/> window_redraw 1
/> draw_window 0 300 0 200 0x000088 1 1 1 0 1 4 hello
/> set_pixel 0 0 0x0000ff
/> set_pixel 1 1 0xff0000
/> set_pixel 2 2 0x00ff00
/> window_redraw 2
/> set_window_caption hi_2there 0
/> dump_win_stack 5
0: 0
1: 1
2: 2
3: 3
4: 4
/> dump_win_pos 5
0: 0
1: 1
2: 2
3: 3
4: 4
/> process_info -1
cpu_usage: 0
window_stack_position: 2
window_stack_value: 2
process_name:
memory_start: 0x00000000
used_memory: 4294967295 (0xffffffff)
pid: 0
box: 220 35 150 200
slot_state: 0
client_box: 5 24 140 171
wnd_state: 0x00
/> get_skin_height
24
/> get_screen_area
0 left
0 top
399 right
299 bottom
/> set_screen_area 0 20 350 250
/> get_screen_area
0 left
20 top
350 right
250 bottom
/> get_skin_margins
6 left
5 top
65 right
3 bottom
/> get_font_size
0px
/> set_font_size 16
/> get_font_size
16px
/> get_screen_size
400x300
/> scrot 016_#f01_#draw_all.out.png
/> disk_del rd

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -50,6 +50,8 @@ get_font_size
set_font_size 16 set_font_size 16
get_font_size get_font_size
scrot umka.rgba get_screen_size
scrot 016_#f01_#draw_all.out.png
disk_del rd disk_del rd

BIN
test/chess_image.rgb Normal file

Binary file not shown.

BIN
test/chess_image.rgba Normal file

Binary file not shown.

View File

@ -1,20 +1,21 @@
UMKA_SHELL=../umka_shell UMKA_SHELL=../umka_shell
xfs_tests := $(addsuffix .out, $(basename $(wildcard *\#xfs_*.t))) xfs_tests := $(addsuffix .out.log, $(basename $(wildcard *\#xfs_*.t)))
s05k_tests := $(addsuffix .out, $(basename $(wildcard *\#s05k_*.t))) s05k_tests := $(addsuffix .out.log, $(basename $(wildcard *\#s05k_*.t)))
s4k_tests := $(addsuffix .out, $(basename $(wildcard *\#s4k_*.t))) s4k_tests := $(addsuffix .out.log, $(basename $(wildcard *\#s4k_*.t)))
f30_tests := $(addsuffix .out, $(basename $(wildcard *\#f30_*.t))) f30_tests := $(addsuffix .out.log, $(basename $(wildcard *\#f30_*.t)))
f70_tests := $(addsuffix .out, $(basename $(wildcard *\#f70_*.t))) f70_tests := $(addsuffix .out.log, $(basename $(wildcard *\#f70_*.t)))
f70s0_tests := $(addsuffix .out, $(basename $(wildcard *\#f70s0_*.t))) f70s0_tests := $(addsuffix .out.log, $(basename $(wildcard *\#f70s0_*.t)))
f70s1_tests := $(addsuffix .out, $(basename $(wildcard *\#f70s1_*.t))) f70s1_tests := $(addsuffix .out.log, $(basename $(wildcard *\#f70s1_*.t)))
f70s5_tests := $(addsuffix .out, $(basename $(wildcard *\#f70s5_*.t))) f70s5_tests := $(addsuffix .out.log, $(basename $(wildcard *\#f70s5_*.t)))
lookup_tests := $(addsuffix .out, $(basename $(wildcard *\#lookup_*.t))) lookup_tests := $(addsuffix .out.log, $(basename $(wildcard *\#lookup_*.t)))
bug_tests := $(addsuffix .out, $(basename $(wildcard *\#bug_*.t))) bug_tests := $(addsuffix .out.log, $(basename $(wildcard *\#bug_*.t)))
xattr_tests := $(addsuffix .out, $(basename $(wildcard *\#xattr_*.t))) xattr_tests := $(addsuffix .out.log, $(basename $(wildcard *\#xattr_*.t)))
unicode_tests := $(addsuffix .out, $(basename $(wildcard *\#unicode_*.t))) unicode_tests := $(addsuffix .out.log, $(basename $(wildcard *\#unicode_*.t)))
v5_tests := $(addsuffix .out, $(basename $(wildcard *\#v5_*.t))) v5_tests := $(addsuffix .out.log, $(basename $(wildcard *\#v5_*.t)))
draw_tests := $(addsuffix .out.log, $(basename $(wildcard *\#draw_*.t)))
all: xfs s05k s4k f30 f70 f70s0 f70s1 f70s5 lookup bug xattr unicode v5 all: xfs s05k s4k f30 f70 f70s0 f70s1 f70s5 lookup bug xattr unicode v5 draw
@echo all tests passed @echo all tests passed
xfs: $(xfs_tests) xfs: $(xfs_tests)
@ -30,8 +31,9 @@ bug: $(bug_tests)
xattr: $(xattr_tests) xattr: $(xattr_tests)
unicode: $(unicode_tests) unicode: $(unicode_tests)
v5: $(v5_tests) v5: $(v5_tests)
draw: $(draw_tests)
%.out: %.ref %.t %.out.log: %.ref.log %.t
$(UMKA_SHELL) < $(word 2, $^) > $@ $(UMKA_SHELL) < $*.t > $@
cmp $@ $< @ cmp $@ $<
@ if [ -f "$*.ref.png" ]; then cmp $*.out.png $*.ref.png; fi

View File

@ -33,6 +33,7 @@
#include "kolibri.h" #include "kolibri.h"
#include "syscalls.h" #include "syscalls.h"
#include "trace.h" #include "trace.h"
#include "lodepng.h"
#define PATH_MAX 4096 #define PATH_MAX 4096
#define FGETS_BUF_LEN 4096 #define FGETS_BUF_LEN 4096
@ -485,6 +486,14 @@ void kofu_draw_rect(int argc, char **argv) {
umka_sys_draw_rect(x, xsize, y, ysize, color, gradient); umka_sys_draw_rect(x, xsize, y, ysize, color, gradient);
} }
void kofu_get_screen_size(int argc, char **argv) {
(void)argc;
(void)argv;
uint32_t xsize, ysize;
umka_sys_get_screen_size(&xsize, &ysize);
printf("%" PRIu32 "x%" PRIu32 "\n", xsize, ysize);
}
void kofu_draw_line(int argc, char **argv) { void kofu_draw_line(int argc, char **argv) {
size_t x = strtoul(argv[1], NULL, 0); size_t x = strtoul(argv[1], NULL, 0);
size_t xend = strtoul(argv[2], NULL, 0); size_t xend = strtoul(argv[2], NULL, 0);
@ -564,18 +573,18 @@ void kofu_blit_bitmap(int argc, char **argv) {
void kofu_scrot(int argc, char **argv) { void kofu_scrot(int argc, char **argv) {
(void)argc; (void)argc;
FILE *img = fopen(argv[1], "w"); uint32_t xsize, ysize;
// const char *header = "P6\n1024 768\n255\n"; umka_sys_get_screen_size(&xsize, &ysize);
// fwrite(header, strlen(header), 1, img);
uint32_t *lfb = kos_lfb_base; uint32_t *lfb = kos_lfb_base;
for (int y = 0; y < 300; y++) { for (size_t y = 0; y < ysize; y++) {
for (int x = 0; x < 400; x++) { for (size_t x = 0; x < xsize; x++) {
uint32_t p = *lfb++; *lfb++ |= 0xff000000;
p |= 0xff000000;
fwrite(&p, 4, 1, img);
} }
} }
fclose(img);
unsigned error = lodepng_encode32_file(argv[1], (const unsigned char *)kos_lfb_base, xsize, ysize);
if(error) printf("error %u: %s\n", error, lodepng_error_text(error));
} }
void kofu_cd(int argc, char **argv) { void kofu_cd(int argc, char **argv) {
@ -876,6 +885,7 @@ func_table_t funcs[] = {
{ "process_info", kofu_process_info }, { "process_info", kofu_process_info },
{ "window_redraw", kofu_window_redraw }, { "window_redraw", kofu_window_redraw },
{ "draw_rect", kofu_draw_rect }, { "draw_rect", kofu_draw_rect },
{ "get_screen_size", kofu_get_screen_size },
{ "draw_line", kofu_draw_line }, { "draw_line", kofu_draw_line },
{ "display_number", kofu_display_number }, { "display_number", kofu_display_number },
{ "set_button_style", kofu_set_button_style }, { "set_button_style", kofu_set_button_style },