public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Miao Xie <miaox@cn.fujitsu.com>
Cc: LTP-ML <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH] Add new testcases for ext4 new features
Date: Fri, 9 Oct 2009 15:43:09 +0200	[thread overview]
Message-ID: <20091009134309.GA8327@schrodinger.suse.cz> (raw)
In-Reply-To: <4ABACAA3.2020206@cn.fujitsu.com>

Hi!
Here comes just a few comments of some parts of the code (sorry for commenting
old patch, the original mail just got stuck, thus resending).

> b/testcases/kernel/fs/ext4-new-features/ext4-inode-version/ext4_test_inode_version.c

> +char *filename;
> +char *filepath;
> +int fd;
> +
> +int old_inode_version;
> +int new_inode_version;

Global variables should be declared as static, otherwise compiler losts track
of unused global variables and doesn't warn you about them.

> +     if (strcmp(argv[1], "create") == 0) {
> +             printf("%d\n", old_inode_version);
> +             return 0;
> +     } else if (strcmp(argv[1], "chmod") == 0) {
> +             test_chmod();
> +     } else if (strcmp(argv[1], "chown") == 0) {
> +             test_chown();
> +     } else if (strcmp(argv[1], "read") == 0) {
> +             test_read();
> +     } else if (strcmp(argv[1], "write") == 0) {
> +             test_write();
> +     } else if (strcmp(argv[1], "mmap_read") == 0) {
> +             test_mmap_read();
> +     } else if (strcmp(argv[1], "mmap_write") == 0) {
> +             test_mmap_write();
> +     } else {
> +             fprintf(stderr, "wrong file operation: %s\n", argv[1]);
> +             return 1;
> +     }

This is just easier and cleaner with defining field of strings (char *) and
looping trough them. Eg:

#define NPARAMS 4

const char *params[NPARAMS] = {"chmod", "chown", "read", "write"};

for (i = 0; i < NPARAMS; i++)
        if (!strcmp(argv[1], params[i})
                break;

Now you have number of selected param in variable i, so traditionall switch()
could be used. Or if called functions have similar type, array of pointers to
them is even easier.

const void (*(func[NPARAMS])(void) = {test_chmod, test_chown, ...};


> +++ b/testcases/kernel/fs/ext4-new-features/ext4-online-defrag/e4defrag.c

Hmm, man 3 free says "if ptr is NULL, no operation is performed"

> +/* Wrap up the free function */
> +#define FREE(tmp)                            \
> +     do {                                    \
> +             if ((tmp) != NULL)              \
> +                     free(tmp);              \
> +     } while (0)                             \

Macro in lowercase is usually considered to be bad practise.

> +/* Insert list2 after list1 */
> +#define insert(list1, list2)                 \
> +     do {                                    \
> +             list2->next = list1->next;      \
> +             list1->next->prev = list2;      \
> +             list2->prev = list1;            \
> +             list1->next = list2;            \
> +     } while (0)
> +


-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  parent reply	other threads:[~2009-10-09 13:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-24  1:25 [LTP] [PATCH] Add new testcases for ext4 new features Miao Xie
2009-09-24  6:23 ` Subrata Modak
2009-10-09 13:43 ` Cyril Hrubis [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-09-28 14:17 Subrata Modak
2009-10-06  7:31 ` Miao Xie
2009-10-24  8:49 Subrata Modak
2009-10-24  8:50 ` Subrata Modak
2009-10-26  7:07 ` Miao Xie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091009134309.GA8327@schrodinger.suse.cz \
    --to=chrubis@suse.cz \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=miaox@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox