2016-12-14

10 Steps to an empty starter project in git with cmake and googletest

Here are 10 Steps to an empty starter project in git (suitable, for instance, for a Coding Dojo), ready to use google test for a starting point for test driven development (Assuming you already have git, cmake and some build toolchain appropriate to your platform installed and available on the execution path).

For the following the numbered item describes the step, the items between the lines of hyphens give steps you can run from a Unix Shell-like program (or Cygwin) to create a basic starter project. Go ahead! Copy them from here and paste them into your favourite shell and it should just all work:

========================================================================================
1. make a new directory (we'll call it starter)
----------------------------------------------------------------------------------------
mkdir starter
----------------------------------------------------------------------------------------

========================================================================================
2. enter it
----------------------------------------------------------------------------------------
cd starter
----------------------------------------------------------------------------------------

========================================================================================
3. create a new git repository
----------------------------------------------------------------------------------------
git init .
----------------------------------------------------------------------------------------

========================================================================================
4. add google test in submods/googletest
----------------------------------------------------------------------------------------
mkdir submods
git submodule add https://github.com/google/googletest.git submods/googletest
----------------------------------------------------------------------------------------

========================================================================================
5. add basic CMakeLists.txt at root
----------------------------------------------------------------------------------------
cat <<eof >CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
project(starter)

include( CTest )

add_subdirectory( submods )

set( starterSourceDir "${PROJECT_SOURCE_DIR}" )

add_executable( starter source/starter_main.cpp )

add_subdirectory( test )
eof
----------------------------------------------------------------------------------------

========================================================================================
6. add basic CMakeLists.txt in submods
----------------------------------------------------------------------------------------
cat <<eof >submods/CMakeLists.txt
cmake_minimum_required(VERSION 3.1)

set_directory_properties(PROPERTIES COMPILE_FLAGS -Wno-error)
add_subdirectory(googletest)
eof
----------------------------------------------------------------------------------------

========================================================================================
7. add basic sourcefile in source
----------------------------------------------------------------------------------------
mkdir source
cat <<eof >source/starter_main.cpp
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    cout << "Hello " << argv[0] << " with " << argc << " parameters (ignored)." << endl;

    return 0;
}
eof
----------------------------------------------------------------------------------------

========================================================================================
8. add basic CMakeLists.txt in test
----------------------------------------------------------------------------------------
mkdir test
cat <<eof >test/CMakeLists.txt
cmake_minimum_required(VERSION 3.1)

add_executable( testStarter test_starter.cpp
)

target_link_libraries( testStarter PRIVATE gtest_main )
target_include_directories( testStarter PUBLIC ../source )

add_test( NAME starterTest COMMAND testStarter )
eof
----------------------------------------------------------------------------------------

========================================================================================
9. add basic GoogleTest file in test
----------------------------------------------------------------------------------------
cat <<eof >test/test_starter.cpp
#include <gtest/gtest.h>
#include <iostream>

using namespace std;
using namespace testing;

TEST(StarterTest, basics)
{
    cout << "Hello test" << endl;
    EXPECT_TRUE(true);
    EXPECT_FALSE(false);
    cout << "Goodbye test" << endl;
}
eof
----------------------------------------------------------------------------------------

========================================================================================
10. Check it all in as an initial commit
----------------------------------------------------------------------------------------
git add CMakeLists.txt
git add submods/CMakeLists.txt
git add test/CMakeLists.txt test/test_starter.cpp
git add source/starter_main.cpp
git commit -m "Initial commit of starter project"
----------------------------------------------------------------------------------------

            __   __          _                _                  _ 
            \ \ / /__  _   _( )_ __ ___    __| | ___  _ __   ___| |
             \ V / _ \| | | |/| '__/ _ \  / _` |/ _ \| '_ \ / _ \ |
              | | (_) | |_| | | | |  __/ | (_| | (_) | | | |  __/_|
              |_|\___/ \__,_| |_|  \___|  \__,_|\___/|_| |_|\___(_)
                                                                   

========================================================================================
And now you're ready to start using your brand new empty project. Write an interface! Write a test for it (it'll fail)! Write code to make it pass! You're on your way with three of the best-of-breed tools available today: git, cmake and googletest.

From the "starter" directory, on Linux, for instance (where cmake's Makefile generator is the default), you can execute the following:
----------------------------------------------------------------------------------------
mkdir build
cd build
cmake ..
make
----------------------------------------------------------------------------------------

Executing the compiled results will also succeed
----------------------------------------------------------------------------------------
./starter
test/testStarter
----------------------------------------------------------------------------------------

And the tests can be run using ctest:
----------------------------------------------------------------------------------------
ctest .
----------------------------------------------------------------------------------------

2016-08-22

Do you use Linux? With a newer NVIDIA card? The 4.7 kernel breaks NVIDIA's binary driver.

Currently, googling doesn't find this data easily, so I thought I'd post it here where an index-crawler might catch it more easily. If you're not very geeky, this post won't make much sense so feel free to pass over it.

If the title made sense to you, here is (a correct-enough version of) the patch you are looking for. Apply this after extracting (-x) the contents of the package, before running ./nvidia-installer in the resulting directory. Otherwise you will have compile errors:

kernel/nvidia-uvm/uvm_linux.h
557,563d556
< static bool radix_tree_empty(struct radix_tree_root *tree)
< {
<     void *dummy;
<     return radix_tree_gang_lookup(tree, &dummy, 0, 1) == 0;
< }
kernel/nvidia-drm/nvidia-drm-gem.c
411c411
<     gem = drm_gem_object_lookup(dev, file, handle);
---
>     gem = drm_gem_object_lookup(file, handle);
kernel/nvidia-drm/nvidia-drm-fb.c
117c117
<     gem = drm_gem_object_lookup(dev, file, cmd->handles[0]);
---
>     gem = drm_gem_object_lookup(file, cmd->handles[0]);

Someone else (the topic poster here) did the "hard work" to find the commits to the kernel that necessitated these changes. 3 months later (this week-end), after the periodic kernel upgrade (to 4.7.1-ARCH-1) "broke" my video driver, I tried to install version 367.35 of the NVIDIA driver for my GeForce GTX 770 video card and could not. "devtalk.nvidia.com" was not a place I thought to look first -- maybe next time it will be -- so I posted it on more of a "user" board after I developed it for myself. The moderator of that board sent me on my way.

Hopefully my title will be easier for the next bloke -- and once 4.7 is more widely used, there'll be many of them -- to find -- until NVIDIA issues a new version of their driver for the newer kernels.

Keywords: NVIDIA video driver, Linux 4.7, "Installation has failed.", "You may find suggestions on fixing installation problems in the README available on the Linux driver download page"

When you hear Fraser Institute, think "Koch-funded"; When you hear "oil sands", think "tar sands"

This evening on my drive home, I heard a piece on the news (before the traffic report; it's a Sunday evening and the migrants are returning) that I couldn't ignore, not after reading Jane Mayer's Dark Money. I'll let the note I wrote to news1130.com in response fill out what what I meant by the title of this post.

(oh fiddlesticks, I forgot to paste it before cobbling together the other links above; oh well, here's what I wrote to the best of my memory)
Subject: The Fraser Institute and the Oil Sands

It does not serve the public interest to quote, as from an acknowledged authority a warning about how a government policy (in this case Alberta's proposed Carbon Tax) will adversely affect the "Oil Sands" that comes from the Fraser Institute without mentioning (a) how frequently the Fraser Institute has received grants of how much from Koch-funded foundations and (b) to what extent Koch family members have invested in the "Tar Sands" (a far more accurate description of Alberta's northern source of petroleum than "oil sands").

It would suffice add "Koch-funded" as an adjective to "Fraser Institute"; and to add "backed by Koch Industries" in mentioning the "Tar Sands".
The news is about informing the public, not just of events and facts but of the meanings and the possible motivations behind those facts and events and I felt that mentioning the Fraser Institute's concerns without mentioning their backdoor connection to the situation did not complete what the news should be about.

2016-06-29

A more palpable Brexit-reversal gesture?

I am not a Brit so my opinion on Brexit didn't count, probably still doesn't but just now, I can't stop myself. I thought it was a bad idea even though I'm old enough to fall into the demographic that voted Leave. I was afraid Brexit was going to succeed and I wish, along with about 4,000,000 Brits who have ostensibly gone on record, that it could be undone.

Maybe it can't, but here's an idea for all you "we-don't-want-to-leave" folks: Keep a pocket-full of Euros and bring them out first when you're trying to buy stuff. It'll be an easy way to all identify yourselves to each other. I know it won't undo the referendum result in the current moment, but it'll be a gesture of solidarity that may start a different kind of groundswell. Also, it can't be IP-spoofed!

Can you imagine merchants across the UK displaying a sign, "Euros accepted here"? It'd put out a different message than 51.9-48.1 did.

2016-03-24

Cross-posted from a web-note to my MP and to the Minister of International Trade

I posted this at Let's Talk TPP (it correctly detected my MP). Here's a cc to my blog and directly to those two e-mail boxes.

To: the Hon. Ron McKinnon, member for Coquitlam -- Por
To: the Hon. Chrystia Freeland, Miniister of International Trade

There is so much to dislike about the TPP that I don't know where to start but here are my hottest hot-button issues:

* I believe supply management safeguards our food supply by making sure we regulate the farmers that are producing the daily staples we all depend on -- especially important for largely fluid based food stuffs as eggs and milk.
* I believe supply management keeps the carbon footprint of these food supplies down which is of net benefit.
* I believe copyrights should expire in a reasonable amount of time. Tying them to "Steamboat Willie" as the US will insist we do will starve out the "Commons" of copyright-expired public domain.
* I believe the US Patent system is broken and until they fix it nobody can afford to make IP treaties with them.
* I believe the TPP was signed illegitimately by a Minister of Trade who knew his legitimacy was fast evaporating and the previous government did not have the moral fortitude to run on the contents of the TPP. It was always trust us. I didn't. Events have shown that I shouldn't have. Accepting the TPP anyway is not part of the change that Canadians voted for. I voted for a party that opposed the TPP. You, Mr. McKinnon said very little at the debate about it either way but the wish of this constituent goes against it directly.

There are many other talking points: TPP-mandated DRM is troubling, right of foreign entities to sue made-in-Canada environmental protections is worse; American patent protections for drug companies will raise our health care costs for no good reason. But all of these only re-inforce my conclusion about this deal:

For the TPP, Canada gives up far too much and gets too little in return. It was negotiated for the benefit of plutocrats and multi-national corporations and too little benefit will "trickle down" (that myth! that old tired lie that Reagan, Thatcher and Mulroney pimped to us 30 years ago! shame, shame...) to us ordinary people. Let it die, please.

Sincerely,

Arthur N. Klassen