all printf calls replaced with kprintf

This commit is contained in:
2022-10-24 18:33:43 +06:00
parent c70544ff97
commit 4785023126
27 changed files with 189 additions and 159 deletions

View File

@@ -11,18 +11,18 @@ void test_all(){
test_dtsod();
test_rng_algorithms();
test_kprint_colors();
printf("\e[96m--------------------------------------\e[0m\n");
kprintf("\e[96m--------------------------------------\e[0m\n");
}
int main(){
setlocale(LC_ALL, "en-US.Unicode");
ktDescriptors_beginInit();
ktDescriptors_initKerepTypes();
ktDescriptors_endInit();
printf("\e[97mkerep tests are starting!\n");
kprintf("\e[97mkerep tests are starting!\n");
// optime("test_all",1,test_all());
test_rng_algorithms();
test_kprint_colors();
ktDescriptors_free();
printf("\e[0m\n");
kprintf("\e[0m\n");
return 0;
}

View File

@@ -4,7 +4,7 @@
int64 _autoarrVsVector(uint16 blockCount, uint16 blockLength){
uint32 count=blockLength*blockCount;
printf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (uint64)count);
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (uint64)count);
Autoarr_int64* ar=Autoarr_create(int64, blockCount, blockLength);
std::vector<int64> vec=std::vector<int64>();
optime("Autoarr_add", 1, ({
@@ -29,7 +29,7 @@ int64 _autoarrVsVector(uint16 blockCount, uint16 blockLength){
}
void test_autoarrVsVector(){
printf("\e[96m-------[test_autoarr_vs_vector]-------\n");
kprintf("\e[96m-------[test_autoarr_vs_vector]-------\n");
_autoarrVsVector(4, 16);
_autoarrVsVector(16, 64);
_autoarrVsVector(32, 32);

View File

@@ -2,7 +2,7 @@
#include "../src/Autoarr/Autoarr.h"
static void printautoarr(Autoarr(uint16)* ar){
printf("\e[94mAutoarr(uint16): "
kprintf("\e[94mAutoarr(uint16): "
IFWIN("%llu", "%lu")
"\n max_blocks_count: %u\n"
" blocks_count: %u\n"
@@ -29,25 +29,25 @@ static void resetar(Autoarr(uint16)* ar){
}
static void printallval(Autoarr(uint16)* ar){
printf("\e[90m");
kprintf("\e[90m");
for (uint16 i=0;i<Autoarr_length(ar);i++)
printf("%u ",Autoarr_get(ar,i));
printf("\n");
kprintf("%u ",Autoarr_get(ar,i));
kprintf("\n");
}
void test_autoarr(){
optime("test_autoarr",1,({
printf("\e[96m------------[test_autoarr]------------\n");
kprintf("\e[96m------------[test_autoarr]------------\n");
Autoarr(uint16)* ar=Autoarr_create(uint16,10,16);
printf("\e[92mautoarr created\n");
kprintf("\e[92mautoarr created\n");
fillar(ar);
printf("\e[92mautoarr filled up\n");
kprintf("\e[92mautoarr filled up\n");
printautoarr(ar);
printallval(ar);
resetar(ar);
printf("\e[92mautoarr values reset\n");
kprintf("\e[92mautoarr values reset\n");
printallval(ar);
Autoarr_free(ar, true);
printf("\e[92mautoarr deleted\n");
kprintf("\e[92mautoarr deleted\n");
}));
}

View File

@@ -15,26 +15,26 @@ const char text[]=
"h: { };";
void print_dtsod(Hashtable* dtsod){
printf("\e[92m");
kprintf("\e[92m");
Hashtable_foreach(dtsod, p,({
printkvp(p);
if(p.value.typeId==ktId_HashtablePtr){
printf(": {\n");
kprintf(": {\n");
Hashtable* sub=p.value.VoidPtr;
Hashtable_foreach(sub, _p,({
printf(" ");
kprintf(" ");
printkvp(_p);
printf("\n");
kprintf("\n");
}));
printf("}");
kprintf("}");
}
printf("\n");
kprintf("\n");
}));
}
void test_dtsod(){
optime(__func__,1,({
printf("\e[96m-------------[test_dtsod]-------------\n");
kprintf("\e[96m-------------[test_dtsod]-------------\n");
Hashtable* dtsod;
char* s;
@@ -49,7 +49,7 @@ void test_dtsod(){
s=r.value.VoidPtr;
}));
DtsodV24_free(dtsod);
printf("\e[92m%s",s);
kprintf("\e[92m%s",s);
optime("reserialize",10,({
tryLast(DtsodV24_deserialize(s),r)

View File

@@ -9,13 +9,13 @@
char data[]="iojihiojopijiugbjmoihftytryfdrh";
#define test_hashfunc(hasht, hashf)({\
printf("\e[94mfunction: \e[92m" #hashf "\n");\
kprintf("\e[94mfunction: \e[92m" #hashf "\n");\
hasht h=0;\
optime("speed test", 1, ({\
for(uint32 i=0; i<SPEED_TESTS; i++)\
h=hashf(h, data, sizeof(data));\
}));\
/*printf("\e[94mhash of \"\e[90m%s\e[94m\": \e[92m%x\n",data, h);*/\
/*kprintf("\e[94mhash of \"\e[90m%s\e[94m\": \e[92m%x\n",data, h);*/\
Autoarr(hasht)* hashes=Autoarr_create(hasht,512,32768);\
optime("collision test",1,({\
uint32 collisions=0;\
@@ -31,15 +31,15 @@ char data[]="iojihiojopijiugbjmoihftytryfdrh";
if(col) collisions++;\
else Autoarr_add(hashes,h);\
}\
printf("\e[93m%u \e[94mcollisions detected in %u hashes\n", collisions, COLLISION_TESTS);\
kprintf("\e[93m%u \e[94mcollisions detected in %u hashes\n", collisions, COLLISION_TESTS);\
}));\
Autoarr_free(hashes, true);\
printf("\e[96m--------------------------------------\n");\
kprintf("\e[96m--------------------------------------\n");\
})
void test_hash_functions(){
optime("test_hash_functions",1,({
printf("\e[96m--------[test_hash_functions]---------\n");
kprintf("\e[96m--------[test_hash_functions]---------\n");
test_hashfunc(uint32, hash_crc32);
test_hashfunc(uint32, hash_sdbm32);
}));

View File

@@ -2,7 +2,7 @@
#include "../src/Hashtable/Hashtable.h"
void print_hashtable(Hashtable* ht){
printf("\e[94mHashtable: "
kprintf("\e[94mHashtable: "
IFWIN("%llu", "%lu")
"\n hein: %u\n"
" height: %u\n"
@@ -14,7 +14,7 @@ void print_hashtable(Hashtable* ht){
}
void printrowgraph(Hashtable* ht){
printf("\e[94mrow length graph:\n");
kprintf("\e[94mrow length graph:\n");
uint16 lgs_l=1000;
uint32 lgs[lgs_l];
for(uint32 i=0; i<lgs_l; i++)
@@ -29,7 +29,7 @@ void printrowgraph(Hashtable* ht){
char* str0=char_multiply(' ',i>=100?0:(i>=10?1:2));
char* str1=char_multiply(' ',lgs[i]>=100?0:(lgs[i]>=10?1:2));
char* str2=char_multiply('#',lgs[i]/100);
printf("\e[94m length: \e[96m%u %s \e[94mfrequency: \e[96m%u %s \e[90m%s\n",i,str0,lgs[i],str1,str2);
kprintf("\e[94m length: \e[96m%u %s \e[94mfrequency: \e[96m%u %s \e[90m%s\n",i,str0,lgs[i],str1,str2);
free(str0);
free(str1);
free(str2);
@@ -63,15 +63,15 @@ Unitype gett(Hashtable* ht){
void test_hashtable(){
optime("test_hashtable",1,({
printf("\e[96m-----------[test_hashtable]-----------\n");
kprintf("\e[96m-----------[test_hashtable]-----------\n");
Hashtable* ht=Hashtable_create();
printf("\e[92mhashtable created\n");
kprintf("\e[92mhashtable created\n");
print_hashtable(ht);
optime("fill",1,fill(ht));
optime("get",1,gett(ht));
printrowgraph(ht);
print_hashtable(ht);
Hashtable_free(ht);
printf("\e[92mhashtable freed\n");
kprintf("\e[92mhashtable freed\n");
}));
}

View File

@@ -6,11 +6,11 @@
#define testColor(COLOR) \
kprint_setColor(kprint_bgBlack | kprint_fg##COLOR);\
printf(#COLOR " ");\
kprintf(#COLOR " ");\
kprint_setColor(kprint_bg##COLOR | kprint_fgGray);\
printf(#COLOR);\
kprintf(#COLOR);\
kprint_setColor(kprint_bgBlack | kprint_fgBlack);\
printf("\n");
kprintf("\n");
void test_kprint_colors(){
/* IFWIN(
@@ -18,15 +18,15 @@ void test_kprint_colors(){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
for(uint8 col=0; col<255; col++){
SetConsoleTextAttribute(hConsole, col);
printf("%u ",col);
kprintf("%u ",col);
}
}),
({
for(uint8 col=0; col<255; col++)
printf("\e[%um%u ", col, col);
kprintf("\e[%um%u ", col, col);
})
);
printf("\n"); */
kprintf("\n"); */
testColor(Black);
testColor(DarkRed);

View File

@@ -10,5 +10,5 @@ EXPORT void CALL test_marshalling(char* text, KVPair** kptr){
}
EXPORT void CALL pinvoke_print(char* msg) {
printf("printed from unmanaged code: %s\n", msg);
kprintf("printed from unmanaged code: %s\n", msg);
}

View File

@@ -3,25 +3,25 @@
#define test_alg(ALG, VALUE_SIZE, EXPECTED_FROM_ZERO){\
printf("\e[94mrng algorithm: \e[96m" #ALG "\n");\
kprintf("\e[94mrng algorithm: \e[96m" #ALG "\n");\
void* s= ALG##_init(0);\
uint##VALUE_SIZE r=ALG##_next(s);\
printf("\e[97m next from zero seed:");\
kprintf("\e[97m next from zero seed:");\
if(r!=EXPECTED_FROM_ZERO){\
printf("\e[91m " IFWIN("%llu\n","%lu\n"), (uint64)r);\
kprintf("\e[91m " IFWIN("%llu\n","%lu\n"), (uint64)r);\
throw(ERR_UNEXPECTEDVAL);\
}\
printf("\e[92m " IFWIN("%llu\n","%lu\n"), (uint64)r);\
kprintf("\e[92m " IFWIN("%llu\n","%lu\n"), (uint64)r);\
ALG##_free(s);\
s= ALG##_initFromTime();\
r=ALG##_next(s);\
ALG##_free(s);\
printf("\e[97m next from time seed:\e[92m " IFWIN("%llu\n","%lu\n"), (uint64)r);\
kprintf("\e[97m next from time seed:\e[92m " IFWIN("%llu\n","%lu\n"), (uint64)r);\
}
void test_rng_algorithms(){
optime("test_rng_algorithms",1,({
printf("\e[96m--------[test_rng_algorithms]---------\n");
kprintf("\e[96m--------[test_rng_algorithms]---------\n");
// for ALG32
// xoroshiro64
test_alg(xoroshiro64star, 32, 932574677ULL)

View File

@@ -14,10 +14,10 @@ Maybe throw_errcode(){
}
Maybe test_maybe(){
printf("\e[94mdont_throw returns \e[92m");
kprintf("\e[94mdont_throw returns \e[92m");
tryLast(dont_throw(),rez0)
printMaybe(rez0);
printf("\n");
kprintf("\n");
try(throw_error(),rez1,;)
printMaybe(rez1);
throw("test_maybe failed");
@@ -29,13 +29,13 @@ Maybe b(){ try(c(),_,;) return MaybeNull; }
Maybe a(){ try(b(),_,;) return MaybeNull; }
void test_safethrow(){
printf("\e[96m-----------[test_safethrow]-----------\n");
kprintf("\e[96m-----------[test_safethrow]-----------\n");
optime("test_safethrow", 1, ({
Maybe e=test_maybe();
printf("\e[94mthrow_error:\n\e[92m");
kprintf("\e[94mthrow_error:\n\e[92m");
printMaybe(e);
Maybe_free(e);
printf("\e[94mthrow_errcode:\n\e[92m");
kprintf("\e[94mthrow_errcode:\n\e[92m");
e=a();
printMaybe(e);
Maybe_free(e);

View File

@@ -2,21 +2,21 @@
#include "../src/SearchTree/SearchTree.h"
void printstnode(STNode* node){
printf("\e[94mSTNode: "
kprintf("\e[94mSTNode: "
IFWIN("%llu", "%lu")
"\n address: %p\n value: ",sizeof(STNode),node);
printuni(node->value);
printf("\n");
kprintf("\n");
// prints pointers to all existing branches
/* printf(" branches: %p\n", node->branches);
/* kprintf(" branches: %p\n", node->branches);
if(node->branches) for(uint8 i=0;i<8;i++){
printf(" \e[90m[%u]=%p\n",i,node->branches[i]);
kprintf(" \e[90m[%u]=%p\n",i,node->branches[i]);
if(node->branches[i])
for (uint8 ii = 0; ii < 8; ii++){
printf(" \e[90m[%u]=%p\n",ii,node->branches[i][ii]);
kprintf(" \e[90m[%u]=%p\n",ii,node->branches[i][ii]);
if(node->branches[i][ii])
for (uint8 iii = 0; iii < 4; iii++)
printf(" \e[90m[%u]=%p\n",iii,node->branches[i][ii][iii]);
kprintf(" \e[90m[%u]=%p\n",iii,node->branches[i][ii][iii]);
}
} */
@@ -24,51 +24,51 @@ void printstnode(STNode* node){
void test_searchtree(){
optime("test_searchtree",1,({
printf("\e[96m-----------[test_searchtree]----------\n");
kprintf("\e[96m-----------[test_searchtree]----------\n");
STNode* node=STNode_create();
printf("\e[92mnode created\n");
printf("push:\e[94m\n ");
kprintf("\e[92mnode created\n");
kprintf("push:\e[94m\n ");
Unitype u=UniInt64(-3);
printuni(u);
ST_push(node,"type", u);
printf(" -> type\n ");
kprintf(" -> type\n ");
u=UniInt64(25);
printuni(u);
ST_push(node,"time", u);
printf(" -> time\n ");
kprintf(" -> time\n ");
u=UniFloat64(-542.00600);
printuni(u);
ST_push(node,"author_id", u);
printf(" -> author_id\n ");
kprintf(" -> author_id\n ");
u=UniInt64(-31255);
printuni(u);
ST_push(node,"channel_id", u);
printf(" -> channel_id\n ");
kprintf(" -> channel_id\n ");
u=UniHeap(ktId_CharPtr, cptr_copy("32.2004"));
printuni(u);
ST_push(node,"message_id", u);
printf(" -> message_id\n ");
kprintf(" -> message_id\n ");
u=UniStack(ktId_CharPtr,"some text UwU");
printuni(u);
ST_push(node,"text", u);
printf(" -> text\n");
printf("\e[92mpull:\e[94m");
printf("\n type -> ");
kprintf(" -> text\n");
kprintf("\e[92mpull:\e[94m");
kprintf("\n type -> ");
printuni(ST_pull(node,"type"));
printf("\n time -> ");
kprintf("\n time -> ");
printuni(ST_pull(node,"time"));
printf("\n author_id -> ");
kprintf("\n author_id -> ");
printuni(ST_pull(node,"author_id"));
printf("\n channel_id -> ");
kprintf("\n channel_id -> ");
printuni(ST_pull(node,"channel_id"));
printf("\n message_id -> ");
kprintf("\n message_id -> ");
printuni(ST_pull(node,"message_id"));
printf("\n text -> ");
kprintf("\n text -> ");
printuni(ST_pull(node,"text"));
printf("\n");
printf("\e[92mfirst node: ");
kprintf("\n");
kprintf("\e[92mfirst node: ");
printstnode(node);
STNode_free(node);
printf("\e[92mnode deleted\n");
kprintf("\e[92mnode deleted\n");
}));
}

View File

@@ -3,12 +3,12 @@
void test_string(){
optime(__func__,1,({
printf("\e[96m-------------[test_string]------------\n");
kprintf("\e[96m-------------[test_string]------------\n");
char c[]="0123456789abcdef";
string s={.ptr=c, .length=cptr_length(c)};
if(s.length!=sizeof(c)-1) throw("string created with incorrect length");
char* p=string_extract(s);
printf("\e[94mstring_extract() -> \e[92m\"%s\"\n",p);
kprintf("\e[94mstring_extract() -> \e[92m\"%s\"\n",p);
free(p);
}));
}

View File

@@ -17,7 +17,7 @@ void test_kprint_colors();
void test_autoarrVsVector();
void test_rng_algorithms();
#define PRINT_SIZEOF(T) printf("\e[94m" #T " size: \e[96m" IFWIN("%llu", "%lu") "\n", sizeof(T))
#define PRINT_SIZEOF(T) kprintf("\e[94m" #T " size: \e[96m" IFWIN("%llu", "%lu") "\n", sizeof(T))
#if __cplusplus
}