master - vdo status: Unit tests + fix bugs
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=2ae4a04710bb2d66a4b7c2d10e56750858f08f04 Commit: 2ae4a04710bb2d66a4b7c2d10e56750858f08f04 Parent: e649f710227a94258699399b02971e010b89b737 Author: Joe Thornber <[email protected]> AuthorDate: Thu May 10 13:01:26 2018 +0100 Committer: Joe Thornber <[email protected]> CommitterDate: Thu May 10 13:01:26 2018 +0100
vdo status: Unit tests + fix bugs
--- device-mapper/vdo/status.c | 28 +++-- device-mapper/vdo/target.h | 7 +- test/unit/Makefile.in | 5 +- test/unit/dmstatus_t.c | 2 +- test/unit/units.h | 2 + test/unit/vdo_t.c | 325 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 353 insertions(+), 16 deletions(-)
device-mapper/vdo/status.c +18 -10
@@ -14,9 +14,11 @@ static char *_tok_cpy(const char *b, const char *e)char *new =malloc ((e - b) +1 );char *ptr = new; -if (new) +if (new) {while (b != e) *ptr++ = *b++; + *ptr ='\0' ; + }return new; }
@@ -131,7 +133,7 @@ static bool _parse_uint64(const char *b, const char *e, void *context)if (!isdigit (*b))return false; - n = (n <<1 ) + (*b -'0' ); + n = (n *10 ) + (*b -'0' ); b++; }
@@ -149,16 +151,17 @@ static const char *_eat_space(const char *b, const char *e)static const char *_next_tok (const char *b,const char *e) { -while (b != e && !isspace (*b)) - b++; +const char *te = b; +while (te != e && !isspace (*te)) + te++; -return b == e ?NULL : b; +return te == b ?NULL : te; } -static void _set_error (struct parse_result *result,const char *fmt, ...) +static void _set_error (struct vdo_status_parse_result *result,const char *fmt, ...) __attribute__ ((format (printf,2 ,3 ))); -static void _set_error (struct parse_result *result,const char *fmt, ...) +static void _set_error (struct vdo_status_parse_result *result,const char *fmt, ...) {va_list ap;
@@ -170,7 +173,7 @@ static void _set_error(struct parse_result *result, const char *fmt, ...)static bool _parse_field (const char **b,const char *e,bool (*p_fn)(const char *,const char *,void *),void *field,const char *field_name, -struct parse_result *result) +struct vdo_status_parse_result *result) {const char *te;
@@ -190,7 +193,7 @@ static bool _parse_field(const char **b, const char *e, } -bool parse_vdo_status (const char *input,struct parse_result *result) +bool vdo_status_parse (const char *input,struct vdo_status_parse_result *result) {const char *b = b = input;const char *e = input +strlen (input);
@@ -228,7 +231,12 @@ bool parse_vdo_status(const char *input, struct parse_result *result)XX (_parse_uint64, &s->total_blocks,"total blocks" );#undef XX - result->result = s; +if (b != e) { +_set_error (result,"too many tokens" ); + goto bad; + } + + result->status = s;return true; bad:
device-mapper/vdo/target.h +3 -4
@@ -55,14 +55,13 @@ void vdo_status_destroy(struct vdo_status *s);#define VDO_MAX_ERROR 256 -struct parse_result { +struct vdo_status_parse_result {char error[VDO_MAX_ERROR ]; -struct vdo_status *result; +struct vdo_status *status; };// Parses the status line from the kernel target. -bool parse_vdo_status (const char *input,struct parse_result *result); - +bool vdo_status_parse (const char *input,struct vdo_status_parse_result *result);//----------------------------------------------------------------
test/unit/Makefile.in +4 -1
@@ -11,6 +11,8 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA UNIT_SOURCE=\ + device-mapper/vdo/status.c \ + \ test/unit/bcache_t.c \ test/unit/bcache_utils_t.c \ test/unit/bitset_t.c \
@@ -22,7 +24,8 @@ UNIT_SOURCE=\ test/unit/framework.c \ test/unit/percent_t.c \ test/unit/run.c \ - test/unit/string_t.c + test/unit/string_t.c \ + test/unit/vdo_t.c UNIT_DEPENDS=$(subst .c,.d,$(UNIT_SOURCE)) UNIT_OBJECTS=$(UNIT_SOURCE:%.c=%.o)
test/unit/dmstatus_t.c +1 -1
@@ -78,7 +78,7 @@ void dm_status_tests(struct dm_list *all_tests)exit (1 ); } -register_test (ts,"/dm/target/mirror/status" ,"parsing mirror status" , _test_mirror_status); +register_test (ts,"/device-mapper/mirror/status" ,"parsing mirror status" , _test_mirror_status);dm_list_add (all_tests, &ts->list); }
test/unit/units.h +2 -0
@@ -30,6 +30,7 @@ void io_engine_tests(struct dm_list *suites);void regex_tests (struct dm_list *suites);void percent_tests (struct dm_list *suites);void string_tests (struct dm_list *suites); +void vdo_tests (struct dm_list *suites);// ... and call it in here. static inline void register_all_tests (struct dm_list *suites)
@@ -44,6 +45,7 @@ static inline void register_all_tests(struct dm_list *suites)regex_tests (suites);percent_tests (suites);string_tests (suites); +vdo_tests (suites); }//-----------------------------------------------------------------
test/unit/vdo_t.c new file +325 -0
325 lines not on this page · raw message