From owner-freebsd-testing@freebsd.org Sun Sep 24 16:22:31 2017 Return-Path: Delivered-To: freebsd-testing@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 64D66E2AF26 for ; Sun, 24 Sep 2017 16:22:31 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-wr0-x22e.google.com (mail-wr0-x22e.google.com [IPv6:2a00:1450:400c:c0c::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id EE1DD7E2D8 for ; Sun, 24 Sep 2017 16:22:30 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-wr0-x22e.google.com with SMTP id g29so4182540wrg.11 for ; Sun, 24 Sep 2017 09:22:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=wEkU7AEHDBE4/x79tAEZgPT143Hk2HHhFje5CIMMttQ=; b=bmEj/DRoCFdUgwMnEGXFqVVKT3ZwVQsAL70mcHJ2kQHXjZ5NnKMxVKAO3nG1PVdVvu DOf0P1AYjs0zYntsRffpuhVogpaRyB8oksmSjzFR79B4GvRhn7GwgLpyeoSV75zatUxH DrwUadcwcnPyZ39zB1lvbKrlZKDyPwbU2C5hkQyK0K4/OLzy2j0YtI+po6T8yPp33+6v t+tqF3mtkPZqASF2jD+IRLfcOF0wa4F12HwXvmtdqgeZcI2oPQYqwR8uTpiA4aDu+O54 juIPwJjceEDuwuLcQLNdXqaaBnEdOTjKlEtwaxgzaBTuOXrDjYL0B82NMIz6LM5Mxkrr 8FqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=wEkU7AEHDBE4/x79tAEZgPT143Hk2HHhFje5CIMMttQ=; b=ml7bL0fSDRWOGboiqd6/GqcdPzuUpbtp6gRdJdnYmqYYD+ASWxpcLANm1/1yn+RuKH JhFGTeRvvztj3E8fBHqPiNkZYNN/qbw0ptln4TKh9MNOHsezx9AhZ/Nczo911cyq+qAf lW4Hf2AHpVnQwXTJ6nphgHp1mpsLpUHhAZb7qPVhss/VsCni0VyfpUrWg87rqRgNqiVd 09WtP6Kcpl6d568m/ZpeHrKdrm10iWiUVV5y+rnJ8IRxsVJkeRUy7vMjNzRwqLQ2Xt1v zKJgJ+HOcso/lYMK7vnIh1Jf3DA9+wIbBkoPtt4qMcovBmOJVe7EaiWUVHphhcAooPX2 +hjA== X-Gm-Message-State: AHPjjUhjBYHy07gPwGesZdPA2KHnNOebZJFacgx0uD/a+KIQI/DQCb2E NIMtiiK2XZQjOlyDl0a2KR0ZEk8ATBIhuwrGypmcZA== X-Google-Smtp-Source: AOwi7QBFqdnxEdJY4UcWJm81rML/FjwaqFhrACJGUGShMiS71UC7HgzUk2fd1sd14q1OYWSWGJlx0bjC6MhquvOgQ3w= X-Received: by 10.46.88.22 with SMTP id m22mr1914603ljb.15.1506270148991; Sun, 24 Sep 2017 09:22:28 -0700 (PDT) MIME-Version: 1.0 Sender: asomers@gmail.com Received: by 10.179.26.6 with HTTP; Sun, 24 Sep 2017 09:22:28 -0700 (PDT) In-Reply-To: <20170924070506.GQ64616@funkthat.com> References: <20170924070506.GQ64616@funkthat.com> From: Alan Somers Date: Sun, 24 Sep 2017 10:22:28 -0600 X-Google-Sender-Auth: 8bYhsZyTNTKdl-TOiGBIrkHGmDA Message-ID: Subject: Re: suggestion library for mocking C functions To: John-Mark Gurney Cc: "freebsd-testing@freebsd.org" Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-testing@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Testing on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Sep 2017 16:22:31 -0000 On Sun, Sep 24, 2017 at 1:05 AM, John-Mark Gurney wrote: > Is there a recommended/supported library for mocking C functions? > > I want to write some test cases for functions that call other code > in the same compilation unit that I want to be able to mock. > > There are a few out there, but was wondering if anyone has suggestions? > > Thanks. > > -- > John-Mark Gurney Voice: +1 415 225 5579 There is no good C mocking library. The language simply doesn't provide a good way to do it. CMockery is the best I've seen. However, it's got some big limitations because it relies on the linker to swap out function implementations. Your other option is to use a C++ mocking library. It's usually possible to build your application as C, but build the tests as C++. However, you'll still need to make a few modifications to the application source to be able to mock functions. You can probably hide it all in the preprocessor. If you go this route, I recommend googletest, which nowadays includes mocking functionality too. https://github.com/google/cmockery https://github.com/google/googletest -Alan