Skip to content

Commit

Permalink
add proc lib
Browse files Browse the repository at this point in the history
  • Loading branch information
rick authored and rick committed Nov 27, 2022
1 parent 5e59292 commit 63b70a0
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 315 deletions.
3 changes: 0 additions & 3 deletions ansi-rgb-utils/ansi-rgb-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ float rgb_to_hue(struct RGB rgb) {
if (range == 0)
return(NAN);


if (rgb.red == max)
hue = fmodf((rgb.green - rgb.blue) / (range), 6);
else if (rgb.green == max)
Expand Down Expand Up @@ -379,15 +378,13 @@ float rgb_to_hsv_value(struct RGB rgb) {
if (!is_in_rgb_range(rgb))
return(-1);


return(get_rgb_max(rgb));
}

float rgb_to_hsv_saturation(struct RGB rgb) {
if (!is_in_rgb_range(rgb))
return(-1);


float value = rgb_to_hsv_value(rgb);

if (value == 0)
Expand Down
2 changes: 0 additions & 2 deletions ansi-utils/ansi-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ size_t ansi_utils_tty_copy(const char *s){
if (!s)
return(0);


printf("s: %s\n", s);
char *enc = b64_encode((const unsigned char *)s, strlen((const char *)s));
printf("enc: %s\n", enc);
Expand Down Expand Up @@ -170,7 +169,6 @@ __attribute__((unused))static bool query_dec_mode(int mode){
if (reply_value == 2 || reply_value == 4)
return(false);


printf("Unrecognised reply to DECRQM: %d\n", reply_value);
return(false);
} while (1);
Expand Down
4 changes: 2 additions & 2 deletions ansi/ansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ static void __attribute__((constructor)) __constructor__ansi(void){
}

////////////////////////////////////////////
int ansi_init(module(ansi) *exports) {
int ansi_init(module(ansi) *exports) {
clib_module_init(ansi, exports);
return(0);
}

void ansi_deinit(module(ansi) *exports) {
void ansi_deinit(module(ansi) *exports) {
clib_module_deinit(ansi);
}
#undef LOCAL_DEBUG_MODE
Expand Down
10 changes: 5 additions & 5 deletions async-test/async-test.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@

#include "ansi-codes/ansi-codes.h"
#include "async-test/async-test.h"
#include "async/async.h"
#include "bytes/bytes.h"
#include "c_fsio/include/fsio.h"
#include "c_greatest/greatest/greatest.h"
#include "c_string_buffer/include/stringbuffer.h"
#include "c_stringfn/include/stringfn.h"
#include "c_vector/vector/vector.h"
#include "log/log.h"
#include "ms/ms.h"
#include "timestamp/timestamp.h"
#include "module/def.h"
#include "module/module.h"
#include "module/require.h"
#include "async/async.h"
#include "ms/ms.h"
#include "timestamp/timestamp.h"

TEST t_async_module1(){
// module(async) *a= require(async);
// module(async) *a= require(async);
PASS();
}

TEST t_async_each_a(){
unsigned long started = timestamp();
size_t out_qty = 0; void **res;
Expand Down Expand Up @@ -216,7 +217,6 @@ SUITE(s_async_v) {
}
SUITE(s_async_module) {
RUN_TEST(t_async_module1);

}
SUITE(s_async_test) {
RUN_TEST(t_async_test1);
Expand Down
114 changes: 62 additions & 52 deletions proc-test/proc-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,104 +7,114 @@
#include "c_stringfn/include/stringfn.h"
#include "c_vector/vector/vector.h"
#include "log/log.h"
#include "module/def.h"
#include "module/module.h"
#include "module/require.h"
#include "ms/ms.h"
#include "proc-test/proc-test.h"
#include "proc/proc.h"
#include "timestamp/timestamp.h"
#include <libproc.h>
#include <sys/proc_info.h>
#include "module/def.h"
#include "module/module.h"
#include "module/require.h"

#include <arpa/inet.h>
#include <assert.h>
#include <CoreFoundation/CoreFoundation.h>
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <utmpx.h>
#include <sys/sysctl.h>
#include <sys/vmmeter.h>
#include <IOKit/IOBSD.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/storage/IOBlockStorageDriver.h>
#include <IOKit/storage/IOMedia.h>
#include <libproc.h>
#include <sys/proc_info.h>
#include <netinet/tcp_fsm.h>
#include <arpa/inet.h>
#include <net/if_dl.h>
#include <pwd.h>
#include <mach/mach.h>
#include <mach/task.h>
#include <mach/mach_init.h>
#include <mach-o/loader.h>
#include <mach/host_info.h>
#include <mach/mach.h>
#include <mach/mach_host.h>
#include <mach/mach_init.h>
#include <mach/mach_traps.h>
#include <mach/mach_vm.h>
#include <mach/shared_memory_server.h>
#include <mach-o/loader.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/storage/IOBlockStorageDriver.h>
#include <IOKit/storage/IOMedia.h>
#include <IOKit/IOBSD.h>

#include <mach/task.h>
#include <net/if_dl.h>
#include <netinet/tcp_fsm.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/proc_info.h>
#include <sys/sysctl.h>
#include <sys/vmmeter.h>
#include <utmpx.h>

static pid_t pid;
static module(proc) *proc;
static module(proc) * proc;

TEST t_proc_test_with_env_key_val(){
char *s;
size_t qty=0;
const char *key="USER",*val="rick";
pid_t *pids=proc->with_env_key_val(key,val,&qty);
asprintf(&s,"%lu/%lu PIDs with env key %s and val %s",
qty,
require(proc)->qty(),
key,val
);
char *s;
size_t qty = 0;
const char *key = "USER", *val = "rick";
pid_t *pids = proc->with_env_key_val(key, val, &qty);

asprintf(&s, "%lu/%lu PIDs with env key %s and val %s",
qty,
require(proc)->qty(),
key, val
);
free(pids);
PASSm(s);
}

TEST t_proc_test_with_env_key(){
char *s;
size_t qty=0;
const char *key="HOME";
pid_t *pids=proc->with_env_key(key,&qty);
asprintf(&s,"%lu PIDs with env key %s",qty,key);
char *s;
size_t qty = 0;
const char *key = "HOME";
pid_t *pids = proc->with_env_key(key, &qty);

asprintf(&s, "%lu PIDs with env key %s", qty, key);
free(pids);
PASSm(s);
}

TEST t_proc_test_pids(){
char *s;
size_t qty=0;
pid_t *pids=proc->pids(&qty);
asprintf(&s,"%lu PIDs",qty);
char *s;
size_t qty = 0;
pid_t *pids = proc->pids(&qty);

asprintf(&s, "%lu PIDs", qty);
free(pids);
PASSm(s);
}

TEST t_proc_test_env(){
char *s;
char *s;
struct Vector *env = proc->pid_env(pid);
asprintf(&s,"PID %d %lu env vars", pid,vector_size(env));

asprintf(&s, "PID %d %lu env vars", pid, vector_size(env));
PASSm(s);
}

TEST t_proc_test_cmdline(){
char *s;
char *cmdline=proc->pid_cmdline(pid);
asprintf(&s,"PID %d cmdline: %s", pid,cmdline);
char *cmdline = proc->pid_cmdline(pid);

asprintf(&s, "PID %d cmdline: %s", pid, cmdline);
PASSm(s);
}

TEST t_proc_test_info(){
char *s;
char *s;
struct kinfo_proc *info = proc->pid_info(pid);
log_info("pid:%d",info->kp_proc.p_pid);
log_info("ppid:%d",info->kp_eproc.e_ppid);

log_info("pid:%d", info->kp_proc.p_pid);
log_info("ppid:%d", info->kp_eproc.e_ppid);
PASS();
}

TEST t_proc_test_cwd(){
char *path = proc->pid_cwd(pid);
char *s;
asprintf(&s,"PID %d path: %s", pid,path);

asprintf(&s, "PID %d path: %s", pid, path);
PASSm(s);
}

Expand All @@ -121,7 +131,7 @@ SUITE(s_proc_test) {
GREATEST_MAIN_DEFS();

int main(int argc, char **argv) {
pid = getpid();
pid = getpid();
proc = require(proc);
GREATEST_MAIN_BEGIN();
RUN_SUITE(s_proc_test);
Expand Down
Loading

0 comments on commit 63b70a0

Please sign in to comment.