Formal verification with Chisel - hdl

Is it possible to do formal verification with Chisel3 HDL language?
If yes, is there an open-source software to do that ?
I know that we can do verilog formal verification with Yosys, but with chisel ?

SpaceCowboy asked the same question here. And jkoening responded it: not now but maybe it will be done.

It's possible to use Yosys-smtbmc with some little hacks described here to «inject» formal properties in Verilog generated.

There is a chisel package named chisel-formal now.
import chisel3.formal._
This extends Module with trait named Formal.
class MyModule extends Module with Formal {
//...
past(io.Mwrite, 1) (pMwrite => {
when(io.Mwrite === true.B) {
assert(pMwrite === false.B)
}
})
cover(countreg === 10.U)
//...
}
That allow to use assert(), assume(), cover(), past(), ... functions.
Full howto is given on github repository.

formal verification is now integrated under chiseltest official test library.

Related

Explanation of Kotlin Syntax for Ktor in Application.kt

I'm new to Kotlin coming from the Python world, and wanted to get into Web Development with Kotlin with Ktor.
Now I've started the tutorial https://ktor.io/docs/creating-interactive-website.html#running-our-application-for-the-first-time and already I don't understand quite a few things.
Looking at the code for Application.kt, which is
package com.jetbrains.handson.website
import freemarker.cache.*
import freemarker.core.HTMLOutputFormat
import io.ktor.application.*
import io.ktor.freemarker.*
import io.ktor.html.respondHtml
import io.ktor.http.HttpStatusCode
import io.ktor.http.content.*
import io.ktor.request.receiveParameters
import io.ktor.response.*
import io.ktor.routing.*
import kotlinx.html.*
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
fun Application.module() {
routing {
static("/static") {
resources("files")
}
}
}
I don't understand what the syntax means. I'm assuming module is an extension function for the class Application? But what does routing and static mean. Can someone explain the concepts happening there, or maybe just name them so I can google them.
Thanks in advance :-)
Edit: For clarification. I know where to look for when it comes to routing concepts and such for ktor. What I am asking is what routing is. Is it a function? But if so what parameters does it take, it does not look like a normal function definition and it is declared inside another function. When I look at the types it seems it takes a lambda function with type Routing.() -> Unit. What does Routing.() mean...
That's what I don't understand.
The routing is an extension function of the Application that installs the Routing plugin and configures it using a provided lambda. The Route.() -> Unit is a function type with the Route receiver (this has type Route inside this function) that has no parameters and that returns Unit (nothing). For more information please read the official Kotlin documentation. So it's the build pattern in action, that allows writing DSLs like Ktor's routing.

How to implement custom platform logic using Kotlin Multiplatform feature?

Kotlin Multiplatform is a good feature to build multiplatform applications, but currently it is (likely) restricted to be intrinsic in Kotlin Multiplatform ecosystem. Can I implement custom build logic to extend the resolution strategy of expect, actual and the like? Or to say treat these features as a general concept of multiplatform, but have different behaviors during build process. Gradle work is welcomed.
For example, if the related extension points were available, one could write a Kotlin compiler plugin to resolve those expect/actual endpoints and maybe compose them into actually platform-specific runtime logic, and then write a Gradle plugin to ultimately process these artifacts.
So if there were two "multiplatform" scenes where both use jvm as "backend", but provide different api with the same or similar logic as "frontend", one could do as above to provide benefits which Kotlin Multiplatform does - write once, run anywhere.
I'd prefer to call this "api-layer multiplatform", to differ that Kotlin Multiplatform is "system-layer multiplatform". "Platform" could be a more abstract one.
So here is what the producer does, just like Kotlin Multiplatform:
build.gradle.kts:
plugins {
kotlin("jvm")
id("<multiplatform-plugin-id>") // Comes with Kotlin compiler plugin too
}
dependencies {
api("<common-dependency-notation>") // Another multiplatform library
}
common module:
fun hello() {
val logger = serviceLogger // Using api from that another multiplatform library
logger.info("Hello")
}
expect fun hookOnStart(block: () -> Unit) // Needs to provide platform-specific implementations
platform module:
actual fun hookOnStart(block: () -> Unit) { // Imaginary
ClientEvents.START.register(block)
}
anotherPlatform module:
actual fun hookOnStart(block: () -> Unit) { // Imaginary
val event = EventFactory.once(ClientStartEvent::class.java, block)
GlobalEventHandler.register(event)
}
As said before, after build, each platform will have its own artifact prepared for runtime or provided as library. He benefits from that another multiplatform library because he could provide each platform with same features through sharing code.
And the following is what the consumer does: (Let's say he's on platform)
build.gradle.kts
plugins {
kotlin("jvm")
}
dependencies {
implementation("<previous-common-dependency-notation>") // From the previous author, mapped to `platform` version
}
Bussiness logic:
fun runBussiness() {
hello()
hookOnStart { serviceLogger.info("world!") }
}
This is pretty uncharted territory and without any documentation.
I'd investigate the source code of the kotlin-multiplatform gradle plugin more in-depth and see if you can extend the existing target palette and expect/actual behaviour.
I'd guess that the plugin isn't really built for this kind of extension, but if you have solid reasons, you could probably submit feature requests and work on a local fork in the meantime.
Update:
If I understood your use-case correctly, you'd like to extend the expect/actual mechanism, which is currently a target/platform based abstraction?
I believe a more general way of making abstractions, such as using interfaces, could serve you. However, I can see the added compile-time safety benefits you seek 🤔, not sure what changes that'd need in the kotlin-multiplatform plugin and if JetBrains team would like that direction. Maybe something Artyom Degtyarev or someone from the JetBrains team could answer?

Can i have my own given when then implementation in Karate for my own keywords? [duplicate]

How do I define my own StepActions class in a Karate test?
All I need is one working example (apparently nobody has an example of this anywhere; I looked and couldn't find anything and so I am asking here).
For example, how would I implement this helper step action in Java? In this case, how do I get access to the WebDriver driver instance from within Java context? Then, how do I call the embed?
#Slf4j
public class SeleniumStepActions extends StepActions {
public SeleniumStepActions(FeatureContext featureContext, CallContext callContext, Scenario scenario, LogAppender appender) {
super(featureContext, callContext, scenario, appender);
}
#When("^screenshot$")
public void takeAScreenShot()
{
// goals is to simulate this in a karate js test
// * def bytes = driver.screenshot()
// * karate.embed(bytes, 'image/png')
log.info("Testing my own custom action.");
}
}
It is possible the above won't work. I am just looking to be pointed in the right direction by someone who knows. I wish there was such an example in the karate demo.
You can't. Which is why there ain't any demo :P
For a detailed discussion, please read this thread: https://github.com/intuit/karate/issues/398
The summary:
Karate does not support the "Step Definitions" that Cucumber does
There are 2 ways to inject custom logic, a) JS, b) Java interop
These are more than sufficient to implement something close to custom "keywords" - see this example: https://twitter.com/KarateDSL/status/1128170638223364097
and another: https://twitter.com/KarateDSL/status/1144458169822806016
If you insist on making your test read like "plain english" (which IMHO is not worth it) - then Karate may not be the best choice for your team.

Karate UI: Can a separate file having a scenario written in plain English be mapped to Karate feature file [duplicate]

How do I define my own StepActions class in a Karate test?
All I need is one working example (apparently nobody has an example of this anywhere; I looked and couldn't find anything and so I am asking here).
For example, how would I implement this helper step action in Java? In this case, how do I get access to the WebDriver driver instance from within Java context? Then, how do I call the embed?
#Slf4j
public class SeleniumStepActions extends StepActions {
public SeleniumStepActions(FeatureContext featureContext, CallContext callContext, Scenario scenario, LogAppender appender) {
super(featureContext, callContext, scenario, appender);
}
#When("^screenshot$")
public void takeAScreenShot()
{
// goals is to simulate this in a karate js test
// * def bytes = driver.screenshot()
// * karate.embed(bytes, 'image/png')
log.info("Testing my own custom action.");
}
}
It is possible the above won't work. I am just looking to be pointed in the right direction by someone who knows. I wish there was such an example in the karate demo.
You can't. Which is why there ain't any demo :P
For a detailed discussion, please read this thread: https://github.com/intuit/karate/issues/398
The summary:
Karate does not support the "Step Definitions" that Cucumber does
There are 2 ways to inject custom logic, a) JS, b) Java interop
These are more than sufficient to implement something close to custom "keywords" - see this example: https://twitter.com/KarateDSL/status/1128170638223364097
and another: https://twitter.com/KarateDSL/status/1144458169822806016
If you insist on making your test read like "plain english" (which IMHO is not worth it) - then Karate may not be the best choice for your team.

Plugin programming on golang

I am coding my project with golang. I want to design my project like plugin programming but I have confused with golang. My project have data analysis task, I purpose make a folder that contain modules analysis, if I have new modules after, I just need copy it to folder and main application will pass data to the new modules without modified.
Can you help me? Thanks for watching!
Go with it's interfaces is a good choice to build something pluggable.
Interfaces
Interface in Go is a way of types abstraction.
Interfaces in Go provide a way to specify the behavior of an object: if something can do this, then it can be used here.
It means a simple but very powerful thing - you can use different composite literals as an interface type if they implement the interface. This is already a pluggable system and if are looking for something simple it is possible to build with minimal effort.
Simplest implementation
Let's say you have such a primitive architecture:
▾ pluggable/
▾ app/
pusher.go
▾ plugins/
green_button.go
plugin_interface.go
red_button.go
main.go
plugins/plugin_interface.go
An interface which will be used as a type abstraction for plugins.
package plugins
type Button interface {
Push()
}
plugins/green_button.go
Now it is possible to extend your application with plugins implement the interface.
package plugins
import (
"fmt"
)
type GreenButton struct {
Msg string
}
func (b GreenButton) Push() {
fmt.Println(b.Msg)
}
plugins/red_button.go
One more plugin...
package plugins
import (
"fmt"
)
type RedButton struct {
Err error
}
func (b RedButton) Push() {
fmt.Println(b.Err)
}
app/pusher.go
An interface type embedded in the composite literal. Any cl implementing the interface could be used in the Pusher instance. Pusher doesn't care about particular plugin implementation it just pushes. It is well abstracted and encapsulated.
package app
import (
"github.com/I159/pluggable/plugins"
)
type Pusher struct {
plugins.Button
}
main.go
Usage of all the stuff.
package main
import (
"errors"
"github.com/I159/pluggable/app"
"github.com/I159/pluggable/plugins"
)
func main() {
alert_pusher := app.Pusher{plugins.RedButton{Err: errors.New("Alert!")}}
success_pusher := app.Pusher{plugins.GreenButton{Msg: "Well done!"}}
alert_pusher.Push()
success_pusher.Push()
}
You can add more sugar, for example one more level of isolation to use a single button configured to be a one or another particular implementation and so on.
Plugins as libraries
Same trick with plugin-libraries. A composite literals declared in a plugin-libraries must implement a plugin interface of the main application. But in this case you will need a register a function and a file with libs imports, so it already looks like a nano plugin framework.
Go 1.8 has support for plugins: https://beta.golang.org/pkg/plugin/. If you can wait a couple months you could use that (or just use the beta 1.8).