00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00027 #include "event-test.h"
00028
00029 RCSTAG("@(#)$Id: t_evg_alloc.c,v 1.3 2005/12/18 00:15:17 klmitch Exp $");
00030
00031 TEST_PROG(t_evg_alloc, "Test operation of event_gen_alloc() and "
00032 "event_gen_release()")
00033 TEST_ARG(t_evg_alloc, "<event-test.tc>")
00034 TEST_ARG(t_evg_alloc, "<engmodule.la>")
00035 TEST_DEP(t_evg_alloc, t_evg_register)
00036
00043 struct t_gen {
00044 ev_genhdr_t tg_hdr;
00045 unsigned int tg_seq;
00046 };
00047
00059 #define cnt(array) (sizeof(array) / sizeof(struct t_gen *))
00060
00067 int
00068 main(int argc, char **argv)
00069 {
00070 int i, fcnt = 0;
00071 char *prog;
00072 ev_err_t err;
00073 ev_ctx_t ctx;
00074 struct t_gen *alloc[25], *gen;
00075 ev_gendesc_t *gd;
00076
00077 ev_test_init(t_evg_alloc);
00078 ev_prog_name(prog, argv);
00079 ev_lib_init(argc, argv, prog, &ctx);
00080
00081
00082 if ((err = event_gen_register(&ctx, EGT_RESERVED, EGT_RESERVED,
00083 sizeof(struct t_gen), 0)) ||
00084 (err = _ev_gen_lookup(&ctx, EGT_RESERVED, &gd))) {
00085 fprintf(stderr, "%s: Unable to register testing generator: "
00086 "error code %u\n", prog, err);
00087 exit(1);
00088 }
00089
00090
00091 TEST_DECL(t_evg_alloc, evg_alloc, "Test that event_gen_alloc() can allocate "
00092 "generators")
00093 for (i = 0; i < cnt(alloc); i++)
00094 if ((err = event_gen_alloc(&ctx, EGT_RESERVED, &alloc[i])))
00095 FAIL(TEST_NAME(evg_alloc), FATAL(0), "Unable to allocate "
00096 "generator %d; error code %u", i, err);
00097 else
00098 alloc[i]->tg_seq = i;
00099
00100 if (gd->gd_active.gl_count == cnt(alloc))
00101 PASS(TEST_NAME(evg_alloc), "Successfully allocated event generators");
00102 else
00103 FAIL(TEST_NAME(evg_alloc), FATAL(0), "Inconsistent generator allocation "
00104 "count; was %u, should be %u", gd->gd_active.gl_count,
00105 cnt(alloc));
00106
00107
00108 TEST_DECL(t_evg_alloc, evg_release, "Test that event_gen_release() can "
00109 "release generators")
00110 for (i = 0; i < cnt(alloc); i += 2)
00111 if ((err = event_gen_release(&ctx, (ev_genhdr_t *)alloc[i])))
00112 FAIL(TEST_NAME(evg_release), FATAL(0), "Unable to release "
00113 "generator %d; error code %u", i, err);
00114 else
00115 fcnt++;
00116
00117 if (gd->gd_active.gl_count == cnt(alloc) - fcnt &&
00118 gd->gd_free.gl_count == fcnt)
00119 PASS(TEST_NAME(evg_release), "Successfully released event generators");
00120 else
00121 FAIL(TEST_NAME(evg_release), FATAL(0), "Inconsistent generator allocation "
00122 "counts; active %u, should be %u; free %u, should be %u",
00123 gd->gd_active.gl_count, cnt(alloc) - fcnt, gd->gd_free.gl_count,
00124 fcnt);
00125
00126
00127 TEST_DECL(t_evg_alloc, evg_realloc, "Test that event_gen_alloc() can "
00128 "resurrect released generators from the free list")
00129 for (i = 0; i < fcnt; i++)
00130 if ((err = event_gen_alloc(&ctx, EGT_RESERVED, &gen)))
00131 FAIL(TEST_NAME(evg_realloc), FATAL(0), "Unable to allocate "
00132 "generator %d; error code %u", i, err);
00133 else if (gen->tg_seq >= cnt(alloc) || gen != alloc[gen->tg_seq])
00134 FAIL(TEST_NAME(evg_realloc), FATAL(0), "Generator allocated is not "
00135 "from the free list; seq is %u but address %p is not %p",
00136 gen->tg_seq, (void *)gen,
00137 (void *)(gen->tg_seq >= cnt(alloc) ? 0 : alloc[gen->tg_seq]));
00138
00139 if (gd->gd_active.gl_count == cnt(alloc) && gd->gd_free.gl_count == 0)
00140 PASS(TEST_NAME(evg_realloc), "Successfully reallocated items from the "
00141 "free list");
00142 else
00143 FAIL(TEST_NAME(evg_realloc), FATAL(0), "Inconsistent generator allocation "
00144 "counts; active %u, should be %u; free %u, should be 0",
00145 gd->gd_active.gl_count, cnt(alloc), gd->gd_free.gl_count);
00146
00147
00148 TEST(t_evg_alloc, evg_destroy, "Test that event_destroy() releases "
00149 "free-listed generators",
00150 (!(err = event_destroy(&ctx))), 0,
00151 ("event_destroy() successfully released free-listed generators"),
00152 ("event_destroy() call failed; error %u", err));
00153
00154 return 0;
00155 }