Exemple #1
0
int test(int M, int N)
{
  Hinit;

  list_t *lists[NO_LISTS];

  build_lists(lists, NO_LISTS, N, M);

  RUN_GC;

  int hit_ratio = 0;
  for (int i = 0; i < N; ++i)
    {
      uint64_t r = RANDOM;
      if (list_contains(lists[r % NO_LISTS], r))
        {
          ++hit_ratio;
        }
    }

  Hexit;
  free_lists(lists, NO_LISTS);

  return hit_ratio;
}
Exemple #2
0
void test_conversion_functions(void) {
    chunk_size memsiz = 1 Mb;
    Priv_mem new_mem = malloc(sizeof(priv_mem));
    new_mem->as = malloc(sizeof(addressspace));
    new_mem->as->start = malloc(memsiz);
    new_mem->as->end = new_mem->as->start + memsiz;
    new_mem->lists = create_lists(new_mem->as->start, memsiz, ASCENDING_SIZE);
    new_mem->functions.manual.alloc        = &manual_alloc;
    new_mem->functions.manual.avail        = &avail;
    new_mem->functions.manual.free         = &priv_free;

    Manual new_manual = (Manual) priv_to_style((Priv_mem) new_mem);

    CU_ASSERT(new_manual->alloc == &manual_alloc);
    CU_ASSERT(new_manual->avail == &avail);
    CU_ASSERT(new_manual->free  == &priv_free);

    Priv_mem compare_priv = (Priv_mem) style_to_priv((Memory) new_manual);

    CU_ASSERT(new_mem->as->start == compare_priv->as->start);
    CU_ASSERT(new_mem->as->end   == compare_priv->as->end);
    CU_ASSERT(new_mem->lists == compare_priv->lists);
    CU_ASSERT(new_mem->functions.manual.alloc == compare_priv->functions.manual.alloc);
    CU_ASSERT(new_mem->functions.manual.avail == compare_priv->functions.manual.avail);
    CU_ASSERT(new_mem->functions.manual.free  == compare_priv->functions.manual.free);

    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Exemple #3
0
//quit
void quit()
{
    free_lists();
    
    config_write();
    SetWindowLong( plugin.hwndParent, GWL_WNDPROC, ( LONG )lpWndProcOld );
}
Exemple #4
0
void test_freelist(void) {
    Manual mem = (Manual) priv_imalloc(1 Mb, MANUAL + ASCENDING_SIZE);
    Priv_mem new_mem = style_to_priv((Memory) mem);
    CU_ASSERT(freelist(new_mem) == new_mem->lists->freelist);

    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Exemple #5
0
void test_priv_free(void) {
    Manual mem = (Manual) priv_imalloc(1 Mb, MANUAL + ASCENDING_SIZE);
    Priv_mem new_mem = style_to_priv((Memory) mem);
    mem->alloc((Memory) mem, 1 Kb);
    void *temp = mem->alloc((Memory) mem, 2 Kb);
    mem->alloc((Memory) mem, 1 Kb);
    CU_ASSERT(memory_start(search_memory(temp, new_mem->lists->alloclist, FALSE)) == temp);
    CU_ASSERT(priv_free((Memory) mem, temp) == 2 Kb);
    CU_ASSERT(memory_start(search_memory(temp, new_mem->lists->alloclist, FALSE)) == NULL);

    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Exemple #6
0
void test_avail(void) {
    Manual mem = (Manual) priv_imalloc(1 Mb, MANUAL + ASCENDING_SIZE);
    mem->alloc((Memory) mem, 1 Kb);
    void *temp = mem->alloc((Memory) mem, 1 Kb);
    mem->alloc((Memory) mem, 1 Kb);
    CU_ASSERT(priv_free((Memory) mem, temp) == 1 Kb);
    CU_ASSERT(avail((Memory) mem) == 1 Mb - 3 * 1 Kb);
    mem->alloc((Memory) mem, 1 Mb - 3 * 1 Kb);
    CU_ASSERT(avail((Memory) mem) == 1 Kb);

    Priv_mem new_mem = style_to_priv((Memory) mem);
    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Exemple #7
0
void test_manual_alloc(void) {
    Manual mem = (Manual) priv_imalloc(1 Mb, MANUAL + ASCENDING_SIZE);
    mem->alloc((Memory) mem, 1 Kb);
    Priv_mem new_mem = style_to_priv((Memory) mem);
    CU_ASSERT(new_mem->lists->freelist->size == 1 Mb - 1 Kb);
    CU_ASSERT(new_mem->lists->alloclist->size == 1 Kb);
    mem->alloc((Memory) mem, 1 Mb - 1 Kb);
    CU_ASSERT(new_mem->lists->freelist == NULL);
    CU_ASSERT(new_mem->lists->alloclist->size == 1 Mb - 1 Kb);
    CU_ASSERT(new_mem->lists->alloclist->next->size == 1 Kb);

    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Exemple #8
0
void test_priv_imalloc(void) {
    Priv_mem new_mem = style_to_priv(priv_imalloc(1 Mb, REFCOUNT + GCD + ADDRESS));
    CU_ASSERT(new_mem->as->end == new_mem->as->start + 1 Mb - 1);
    CU_ASSERT(new_mem->lists->freelist->size == 1 Mb);
    CU_ASSERT(new_mem->lists->freelist->next == NULL);
    CU_ASSERT(new_mem->lists->alloclist == NULL);
    CU_ASSERT(new_mem->lists->sort_style == 4);
    CU_ASSERT(new_mem->functions.managed.rc.retain == &retain);
    CU_ASSERT(new_mem->functions.managed.rc.release == &release);
    CU_ASSERT(new_mem->functions.managed.rc.count == &count);
    CU_ASSERT(new_mem->functions.managed.gc.alloc == &typed_alloc);
    CU_ASSERT(new_mem->functions.managed.gc.collect == &collect);

    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Exemple #9
0
void test_typed_alloc(void) {
    char *tmp_gc;

    Managed mem_gc = (Managed) iMalloc(1 Mb, GCD + ASCENDING_SIZE);
    Priv_mem priv_mem_gc = style_to_priv((Memory) mem_gc);

    // Test allocating 10 pointers, 5 ints and 8 chars
    tmp_gc = mem_gc->gc.alloc((Memory) mem_gc, "10*5i8c");
    CU_ASSERT(alloclist(priv_mem_gc) != NULL);
    CU_ASSERT(alloclist(priv_mem_gc)->size == 10 * sizeof(void*) + 5 * sizeof(int) + 8 * sizeof(char));
    CU_ASSERT(freelist(priv_mem_gc) != NULL);
    CU_ASSERT(freelist(priv_mem_gc)->size == (1 Mb - (10 * sizeof(void*) + 5 * sizeof(int) + 8 * sizeof(char))));

    free_lists(priv_mem_gc->lists);
    free(priv_mem_gc->as->start);
    free(priv_mem_gc);
}
Exemple #10
0
int		nm_macho(char *f, char *ptr, uint8_t mask)
{
	t_sym						**sym_lst;
	t_sect						**sect_lst;

	sym_lst = malloc(sizeof(t_sym *));
	sect_lst = malloc(sizeof(t_sect *));
	*sym_lst = NULL;
	*sect_lst = NULL;
	if (f)
		ft_printf("\n%s:\n", f);
	if (parse_lc(sym_lst, sect_lst, ptr, mask) == -1)
		return (EXIT_FAILURE);
	sort_sym_lst(sym_lst);
	disp_sym_lst(*sym_lst, *sect_lst);
	free_lists(sym_lst, sect_lst);
	return (EXIT_SUCCESS);
}
Exemple #11
0
int main(int argc, char **argv) {
    // check options passed
    if (argc != 2) {
        printf("\nInvalid argument list. Please use '--help' for usage.\n\n");
        return -1;
    }
    // print help 
    if (strcmp("--help", argv[1]) == 0) {
        printf("\nUsage : %s <dump file name>\n", argv[0]);
        printf("\tEx : %s traceroute.pcap\n\n", argv[0]);
        exit(0);
    }
    // pcap file pointer
    pcap_t *pcap_p;
    // error buffer to hold errors on pcap call
    char errorbuf[PCAP_ERRBUF_SIZE];
    // initialize all lists used
    init_lists();

    // open dump file
    pcap_p = pcap_open_offline(argv[1], errorbuf);
    if (pcap_p == NULL) {
        printf("Error while opening dump file.\n%s\n", errorbuf);
        exit(0);
    }
    // check whether the link layer type is Ethernet, return otherwise
    if (pcap_datalink(pcap_p) != DLT_EN10MB) {
        printf("Dump file provided is not captured from Ethernet.\n");
        exit(0);
    }    
    // read all packets from dump file 
    if (pcap_loop(pcap_p, 0, callback_handler, NULL) == -1) {
        printf("Error while reading dump file.\n");
        exit(0);
    }
    // close the pcap file
    pcap_close(pcap_p);       
    // print results stored in lists
    print_results();
    // free memory allocated for lists
    free_lists();
    return 0;
}
Exemple #12
0
void free_lists(struct list *temp)
{
    if(temp)
    {

        if(temp->next==NULL)
        {
            free(temp);
            return;
        }
        else
            {
                free_lists(temp->next);
                
            }
    }


}