From owner-freebsd-hackers@FreeBSD.ORG Fri Jun 24 15:55:08 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (unknown [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 808F5106564A for ; Fri, 24 Jun 2011 15:55:08 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-qy0-f175.google.com (mail-qy0-f175.google.com [209.85.216.175]) by mx1.freebsd.org (Postfix) with ESMTP id 19EE18FC14 for ; Fri, 24 Jun 2011 15:55:07 +0000 (UTC) Received: by qyk30 with SMTP id 30so423773qyk.13 for ; Fri, 24 Jun 2011 08:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=BbB2yC3phj4kpCHTbYKll9ZqEbNaWK3RQ9mLtzunzbQ=; b=CUPIv2qdu2yhijyUr8oTZOFVcD60S7eQ+WInBZxe9xHURXFKgr4g7NSpQH3MwWRh/F 52KWjKbsKmZiQX363kn9vhqo2snU8aqf3hRnnFkiK1B4mBFryYtywTfYPybrZptgb9eU B5uB4j8VWGIX0tem4GBi7DDfsiay2F7Z/BHh4= MIME-Version: 1.0 Received: by 10.229.63.141 with SMTP id b13mr494364qci.245.1308930907250; Fri, 24 Jun 2011 08:55:07 -0700 (PDT) Sender: mdf356@gmail.com Received: by 10.229.220.68 with HTTP; Fri, 24 Jun 2011 08:55:07 -0700 (PDT) In-Reply-To: <201106240914.49279.jhb@freebsd.org> References: <4E043B5F.3080908@embedded-brains.de> <201106240914.49279.jhb@freebsd.org> Date: Fri, 24 Jun 2011 08:55:07 -0700 X-Google-Sender-Auth: JiAuOQFcbqjbz7CFdBFkC-aBv_I Message-ID: From: mdf@FreeBSD.org To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org, Sebastian Huber Subject: Re: Unit Tests for FreeBSD Kernel APIs? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2011 15:55:08 -0000 On Fri, Jun 24, 2011 at 6:14 AM, John Baldwin wrote: > On Friday, June 24, 2011 3:23:11 am Sebastian Huber wrote: >> Hello, >> >> exists there some unit tests for FreeBSD kernel APIs, e.g. mutex(9), >> condvar(9), etc.? >> >> Have a nice day! > > Hmm, I have a kernel module that does some tests, but it is not in the tr= ee. > One of the issues is that many of the tests you want to do for some of th= ese > APIs involve timing. =A0For rwlocks, for example, I used KTR traces and u= sed > a kernel module that forked 4 threads to all compete over a single lock. = =A0I > then verified via KTR traces that every branch was taken (and made libera= l > use of KASSERT()s which caught a few edge cases I had missed initially). At $WORK we have a generic TEST_THREAD interface which allows for calling essentially random kernel code (whatever a dev codes up) with arguments. At the shell one types "test_thread foobar(12345, \"string\")" or whatever args. The test_thread syscall looks in the set of registered functions for foobar, and passes off a string with (12345, \"string\") to the function. Each function is responsible for parsing its own arguments. The args for the test_thread function pointer are the $WORK equivalent of and input sbuf and and output sbuf, which is copyout'd to the calling binary. If there's interest I can clean up the patch a little to show proof-of-concept that builds without all the $WORK gorp. We use this for a few things: unit-testing kernel code, hand-editing of filesystem data to recover customer sites from kernel bugs (sometimes this is possible), etc. Cheers, matthew