Random generate Simulink models

Differential testing is a well-known technique in compiler testing. In our recent research project, we use this approach to random-test (aka fuzz) Simulink, the popular model-based design tool by MathWorks. Check out the project homepage for an early prototype implementation of our testing scheme which randomly generates (valid) Simulink models and applies differential testing technique to find bugs in Simulink. The project is open source and we welcome new contributors!

Python 3 Read from Standard Input (stdin) Like C or Java

I will be using Python3 to read from standard input (or console). I will present two ways of doing this.

First Example

Input (data.txt)

First line of input will contain an integer which tells how many of lines (of data) will follow up. In each of the following lines, there will be one integer and and one floating-point (decimal) number, separated by a space:

1 2.3
3 4
5 6.0

Code (iotest.py)

if __name__ == '__main__':
    # Reading the first line and converting it to an integer
    num_entries = int(input())

    # Running a for loop to read each of the following lines
    for i in range(num_entries):
        current_line = input()
        # Getting the two values separated by space in variables `a` and `b`
        a, b = current_line.split()
        a, b = int(a), float(b)
        print(a, b)

Run the program

python3 iotest.py < data.txt

Second Example

Input (data.txt)

In this example, data file exactly looks like the one from first example, except that the first line is missing. Which means, we do not know how many data to read. We would have to run a while loop to read lines till there is and EoF (End of File) which tells us there is nothing more to read.

1 2.3
3 4
5 6.0

Code (iotest2.py)

if __name__ == '__main__':
        # Running a while loop since we don't know how many lines to read.
        while True:
            current_line = input()
            # Getting the two values separated by space in variables `a` and `b`
            a, b = current_line.split()
            a, b = int(a), float(b)
            print(a, b)
    except EOFError:
        # There is nothing more to do when we reach End of File (EOF)


python3 iotest2.py < data.txt

Concluding Notes

  • You can run the programs without saving input data in a file. Just type python3 iotest.py and then enter data.
  • Be sure to use Python 3 only as the code will not work in Python 2
  • We are using input() built-in method of Python 3 which reads a single line and returns it as a string. So we have to convert them to appropriate data type (int/float).

Collaborating using git: make merging less painful!

Hi, I’m Shafiul! Me along with Ibrahim & Sifat are working in a project which we maintain using git. We’ve decided to follow a simple protocol to merge our works effeciently in a painless way!

All of us will work in our own branches (learn first about branching if you’re not familiar with it). At the end of the day, the one who finishes his work after the rest of the team, should merge all of our works!

Say, after working all day long, I figured out Ibrahim was still working before I went to bed. So it became Ibrahim’s due responsibility to merge everyone’s work 🙂

The first step is: create a new branch for you, where only you will work, and no one else will touch.

Create a new Branch named “shafiul”:

git branch shafiul

To work in this branch, I need to check-out to work in this branch:

git checkout shafiul

While working, Commit any time:

git add -A
git commit -m "Message"

When you’re done, push your commits to the server:

git push origin shafiul:shafiul

Note the command: It pushes your commits made in local “shafiul” branch to origin’s (server’s) “shafiul” branch.

Like me, Ibrahim & Sifat has also crated their own branches named “ibrahim” & “sifat” and they’re working in their branches.

Merging everybody’s work

The one who will be merging has to do followings:
First, download everyone’s commits from origin (server) to his local machine:

git fetch origin shafiul:shafiul
git fetch origin ibrahim:ibrahim
git fetch origin sifat:sifat

Now time to merge. Check-out to master branch. With this branch, we will merge all other branches.

git checkout master

Now merge all other branches with master:

git merge shafiul
git merge ibrahim
git merge sifat

Cool! master is now merged with everyones code (Congratulations if no conflicts has occurred. But don’t get panicked if conflicts occur, to learn how to resolve conflicts, see the end of this article) – now Push your local “master” to origin (server):

git push origin master:master

Everyone’s duty: Update your branches…

The next day, before working, everyone should update their branches. First, everyone needs to pull updated “master” branch from origin (server) and merge it with your local copy of master branch:

git checkout master
git pull origin master:master

Now your local copy of master branch is updated. Finally, checkout to your own branch and merge it with updated master:

git checkout shafiul
git merge master

Qt Error: undefined reference to `vtable for

I was receiving this error once, when I was trying to add signals & slots to one of my classes. I figured out that Qt was having problems with moc files, and there were no moc files being generated.

To solve the problem, I specified “moc directory” in the project’s .pro file:

OBJECTS_DIR = debug/obj
MOC_DIR = debug/moc

And my problem was solved 😀